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:
Untitled1
.// My first hello world program. console.log("Hello World");
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.
hello.js
. Now, you should see the tab title is changed from Untitled1
to hello.js
. Now Cloud9 knows this is JavaScript program. It will highlight the program with different colors.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.
3.129.218.69