First Program in Javascript, Hello World

Rumman Ansari   Software Engineer   2023-03-26   5623 Share
☰ Table of Contents

Table of Content:


Developer Environment

What do you need to develop JavaScript? The answer is simple - any web browser such as Internet Explorer, Chrome, or Firefox.

Most browsers come up with developer tools that allow us to,

  • View the page that is rendered on the browser
  • View the HTML and JavaScript code
  • Debug JavaScript code
  • View console tab to take input commands.

Console

Console is a simple text interface to input commands and view output. You can access the console by navigating to Developer Tools menu from the browser options. This comes handy for debugging.

Simply say console.log(“Hello World”); and try it out.

Syntax
  • JavaScript is an interpreted language and requires no compilation.
  • JavaScript is case sensitive and constitutes statements.
  • The semicolon is the best way to separate the statements.
  • JavaScript is insensitive to whitespace.
  • Script tags holding JavaScript code are best placed at the end of the code.
  • Comments start with // or /* and */

Script code

Javascript example is easy to code. JavaScript provides 3 places to put the JavaScript code: within body tag, within head tag and external JavaScript file.

Let’s create the first JavaScript example.


<script type="text/javascript">  
document.write("JavaScript is a simple language for atnyla learners");  
</script>  

The script tag specifies that we are using JavaScript.

The text/javascript is the content type that provides information to the browser about the data.

The document.write() function is used to display dynamic content through JavaScript. We will learn about document object in detail later.