Related post

Inheritance in Java programming with example | Zhullyblog

JavaScript syntax - Zhullyblog

JavaScript Syntax



Hey, welcome to zhullyblog. If this is your first time here , please Subscribe to Zhullyblog by Email to get latest tutorial.



JavaScript Syntax


I said earlier in the introduction to JavaScript that JavaScript are placed in HTML to create webpages. JavaScript works hand in hand with HTML which means that the code in JavaScript needs to load along side with the markup language.

This will lead us to placing JavaScript within our HTML document or creating a link within the HTML document and JavaScript document. Click here to see tutorials on HTML

The JavaScript <script>.....</script> tag are placed within HTML code for implementation.
The <script> tag contains your JavaScript code and can be placed anywhere within your HTML document but it is advisable to place them within the <head> tag.
The <script> tag alerts the editor that a JavaScript code will be added and once you are done with your JavaScript </script> tag informs the editor that JavaScript code has ended.

JavaScript Syntax




<script language = "javascript" type = "text/javascript">
             The code goes here
    </script>

   


The script tag takes two important attribute just like in CSS. The attributes are :
   Language : This attribute specifies the language you are using. Since you are using JavaScript, it will take the value JavaScript.
   Type - This takes the value text/JavaScript
This is how the code will be placed within HTML document.




<!DOCTYPE html>
<html lang="en">
<head>
  <title> Adding JavaScript to HTML</title>
  </head>
  <script language ="javascript" type="text/javascript">

  </script>
</body>
</html>
 Screenshot

JavaScript syntax


Since you are now familiar with JavaScript let's take an example. Ooh yes , the best example to take is Hello world. On your text editor which can either be Visual basic or noedpad, save your file as hello.js.

Let's breakdown the example
The first part is HTML. Click here to learn HTML.

 • <script language = "javascript" type=" text/javascript">
This is the beginning of your JavaScript code
  • </script>
Ends the JavaScript code.


Now that we are familiar with JavaScript, let's talk about case sensitivity.

JavaScript is case-sensitive. This implies that variable , keywords and function name should be carefully typed. Once you declare a variable, the variable name must remain the same throughout. Once you alter any letter, there will be a problem.
In JavaScript, var is different from Var. So you should take note of this.

Semicolon in JavaScript
Semicolon are used in JavaScript just like other programming language like C++ , Java. You make use of semicolon when you place a statement on a single line but you can omit comment when you have statement in separate line. You will understand that better soon as we move on.






Please share















Where do you place JavaScript in HTML document

JavaScript Variables

JavaScript Strings: How to create and manipulate

JavaScript If, If else, If else if statement

JavaScript Function: How to define and call a function

How to generate output in JS

JavaScript Switch case


Comments