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

  • Programming the BeagleBone
  • Yogesh Chavan
  • 338字
  • 2021-07-23 14:36:46

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.

主站蜘蛛池模板: 顺平县| 安陆市| 佳木斯市| 洪湖市| 敦化市| 密云县| 英德市| 南皮县| 盐津县| 交口县| 天柱县| 尤溪县| 洛扎县| 阳高县| 齐齐哈尔市| 墨竹工卡县| 犍为县| 临西县| 张家港市| 瓮安县| 温泉县| 大洼县| 阿城市| 清河县| 白城市| 聂拉木县| 丹阳市| 三原县| 甘肃省| 乐亭县| 浦北县| 马龙县| 三门峡市| 延津县| 长汀县| 海口市| 扎鲁特旗| 梁平县| 南和县| 改则县| 安仁县|