JavaScript-Hello World

 Hello World 

When you are ready to start experimenting with longer chunks of code, these line-byline interactive environments may no longer be suitable, and you will probably prefer to write your code in a text editor. From there, you can copy and paste to the JavaScript console or into a Node session. Or you can save your code to a file (the traditional filename extension for JavaScript code is .js) and then run that file of JavaScript code with Node: 

$ node snippet.js

 If you use Nodein a noninteractive manner like this, it won’t automatically print out the value of all the code you run, so you’ll have to do that yourself. You can use the function console.log() to display text and otherJavaScript values in your terminal window or in a browser’s developer tools console. So, for example, if you create a hello.js file containing this line of code: 

console.log("Hello World!");

and execute the file with node hello.js, you’ll see the message “Hello World!” printed out. If you want to see that same message printed out in the JavaScript console of a web browser, create a new file named hello.html, and put this text in it: 

<script src="hello.js"></script>

Then load hello.html into your web browser using a file:// URL like this one: 

file:///Users/username/javascript/hello.html

 Open the developer tools window to see the greeting in the console.

Post a Comment

Previous Post Next Post