官术网_书友最值得收藏!

Hello World program

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:

  1. Go to the File menu. Click on the New File button. You will see a new code editor tab opened with title Untitled1.
  2. 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.

  3. Go to the File menu again and save as 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.
  4. 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.

Explanation

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.

主站蜘蛛池模板: 屏东市| 长寿区| 揭阳市| 金溪县| 彝良县| 平定县| 平定县| 泸水县| 麻阳| 泰兴市| 谢通门县| 呼和浩特市| 西宁市| 南和县| 高邑县| 隆尧县| 奎屯市| 绥阳县| 田东县| 万年县| 潢川县| 康平县| 惠安县| 和林格尔县| 大化| 安顺市| 铜陵市| 科技| 红河县| 淳安县| 和静县| 湛江市| 西宁市| 兴国县| 精河县| 桐乡市| 彭阳县| 梓潼县| 南康市| 娄底市| 荃湾区|