Wednesday, March 23, 2016

Hello World in JavaScript



First steps in the JavaScript Programming World by writing the famous Hello World script [Wiki]. This program is very popular and if you are interested, there is a list of implementations in various languages [Wiki].


Here, I assume that your configuration previously described [Link] is fine.

1. Create your first script

Run ImageJ and go to Plugins > New > JavaScript, a window entitled Script.js is created , then copy the following code and paste it in the window Script.js :
var text = "Hello World!";
IJ.log(text);

Save this file in File > Save As... (Fig.1) and choose the location and file name.

Note: As I already said [Link], the most convenient way is to store all of your scripts in the directory ImageJ > plugins > CrazyBio_Learning_JS

Fig.1: Save your script by clicking the File > Save As... menu item of the JavaScript window. 

In this window, go to the menu Macros > Run Macros or use the shortcut Ctrl + R and a new window Log is displayed with the text Hello World! (Fig.2).

Congratulations!! this is your first program. Easy, isn't it?
Fig.2: Result of your Hello World! script.

In this two-lines script,
  1. First, we declare a variable named text and assign to it the sentence "Hello World!".
  2. Second, we print in the ImageJ Log window, the value contained in the variable text thanks to the function IJ.log(...).


2. Other crazybiocomputing posts

Further readings are available in ...
  • Programming in JavaScript Series  [Link]
  • Image Processing TOC [Link]

1 comment:

  1. Everything is fine, am happy about your blog. Thanks admin for sharing the unique content, you have done a great job I appreciate your effort and I hope you will get more positive comments from the web users.
    school branding uk

    ReplyDelete