Let's do a quick and dirty Hello World
JavaScript program. In this program, we are just printing Hello World
in the console view provided by Cloud9:
Go to the File menu. Click on the New File button. You will see a new code editor tab opened with title
Untitled1
.Write the following code in the code editor view:
// My first hello world program. console.log("Hello World");
Tip
Downloading the example code
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Go to the File menu again and save as
hello.js
. Now, you should see the tab title is changed fromUntitled1
tohello.js
. Now Cloud9 knows this is JavaScript program. It will highlight the program with different colors.Click on the run button at the top of screen. You will see the Debugger toolbar from right side is expanded to the Debug pane. Click on the Resume button on expanded pane or press the F8 key. You should see the
Hello World
text in the output view at the bottom.
In this tiny code, the first line is the comment. JavaScript supports C and C++ style commenting. So the pattern /* ... */
is used in multi-line commenting and the pattern//
is used for single line commenting. The second line is calling the log()
method on the object console
. We have given the string Hello World
as a parameter to the log()
method. A semicolon ;
denotes a terminated statement. Here, the console
object provides access to the browser's debugging console. console.log()
is a method to print string. It prints Hello World
in the console.
As we are using a built-in JavaScript object, we have not loaded a JavaScript module/library. You can try more methods provided by the console object. You can get a detailed document about JavaScript at: http://www.w3schools.com/js/ and https://developer.mozilla.org/en-US/docs/Web/JavaScript.