Basic Syntax And Rules In JavaScript

(adsbygoogle = window.adsbygoogle || []).push({});

(adsbygoogle = window.adsbygoogle || []).push({});

Welcome back, guys! I hope you are well and having a great day. In today’s tutorial, I will discuss the new topic “ Basic Syntax and Rules in JavaScript” .
Learning grammar for a spoken language is necessary before you start writing it. There are rules and regulations you have to follow to write. Similarly, all programming languages have their grammar/syntax and rules which you have to follow in order to execute.
JavaScript Is Case Sensitive

JavaScript is case sensitive programing language. Therefore variables, function names, language keywords and any other identifiers must have written with a consistent capitalization of letters.     

Let me show you an example. 

In this statement “ alert” is case sensitive and if I change the first letter of “alert”  “A”.

Alert(“I am learning JavaScript”);
This code sample has uppercase “A” and instead of printing the expected “I am learning JavaScript”. The error will appear (alert is not defined) and code would not run. So it is important to be careful with syntax.  Here are some rules you should keep in mind. 

JavaScript keywords such as if, for and alert are always lowercase.
Built-in objects such as math and date are uppercase or capitalized.
DOM(Document Object Model)  are usually lowercase but the methods are often a combination of lowercase and uppercase.

(adsbygoogle = window.adsbygoogle || []).push({});

Variable, Function & Objects Name

You can define or name your own variable, function and objects.
There is no limit in choosing their name you can use uppercase, lowercase and underscore(_) or Numbers.
The name must begin with letters or underscore and it can’t start with a number i.e getAgeBy_Name,  getHeightUnder_2
There is no limit for you in choosing a variable name with uppercase or lowercase, as I told before JavaScript is case sensitive: age, Age, AGE will be considered as three different variables.
So make sure to use the same variable when calling it or referring.
Most of the code in JavaScript is a statement. Like, this is a statement of JavaScript.

alert(“I am learning JavaScript on”); 

Statement can be used to change the color of webpage, background or position of picture etc
Always put a semicolon at the end of the statement because each statement in JavaScript ends with a semicolon.
White space is not sensitive. You can add spaces and line-breaks as much as you want.

Syntax of JavaScript Comment
The syntax of comment is similar to CSS. JavaScripts c omments are used to explain or understand the code, and to make it more readable. Suggestions...