JavaScript Syntax

JavaScript Syntax

In computer science, the syntax of a computer language (aka programming language ) is the set of rules that defines the structure of a programming language. And a computer programmer should follow these rules in order for the program to work.
JavaScript syntax refers to a set of rules that determine how the language will be written (by the programmer) and interpreted (by the browser).
Shortly, as a programmer, you have to follow some rules in order for the program to work. If you don’t follow or write incorrectly your computer and ‘browser’ (in this case javascript runs in a browser) don’t understand, and you will get an error.

It would take much more than a short tutorial to cover the complete JavaScript syntax. However, this tutorial covers the syntax basics that will enable you to code JavaScript in a proficient manner.
You will learn more syntax as you progress or learn more Javascript.

JavaScript Variables

In a programming language, variables are used to store data.
Data is anything that is meaning to a computer.
An important part of programming is learning how to save data.
Variables are easy to create.
Javascript uses the var keyword to create or declare a variable.
An equal sign is used to assign values to variables.
Like this:

var a;
a = 5;

In the example above var a; means there is ‘a variable’ called ‘a’
And a = 5; means its value or data is 5

Where to put your scripts?

You can place your scripts in any of the following locations:

  •  Inside the HTML document’s  head tags.
  • Within the HTML document’s body (i.e. between the body tags).
  • In an external file (and link to it from your HTML document) using
     <script src="file-location.js">   </script> 

Case Sensitivity in JavaScript

JavaScript is case-sensitive. This means that variables, language keywords, function names, and other identifiers must always be typed with a consistent capitalization of letters.

For example, the variable myName must be typed exactly as  myName   not  MyName  or  myname .

 Similarly, the method name getElementById() must be typed with the exact case, not as getElementByID().

Example Code

var myName = "Lia Sue Kim";

If you checkout the browser console by pressing the f12 key on the keyboard, you’ll see a line something like this: 

Uncaught ReferenceError: MyName is not defined

Comments are closed.

Let's make it official :) Subscribe to my Youtube Channel.