- it is a case sensitive language.
- every statement ends with a semicolon (;).
- variables can be started from an alphabetical digit or an underscore (_).
- variable Values
- fixed Values
For example, a variable “x” is defined below:
Types of variables
Global variables: Global variables are those which we can access from anywhere in the code. These variables are declared from the outside of the function.
Local variables: Local variables are those which are declared inside a function and cannot be accessed from outside of the function.
// Function definition
// Local variable declaration
var num = 45;
// Display the value of Global variable
// Display the value of local variable
document.writeln("<br>" + num );
// Function call
Fixed values are known as literals or constant values.
Numbers: Numbers are the numeric values with or without decimals. The syntax of numbers is given below.
Strings: Strings are in text form; this text is written within quotes. The syntax of the string is given below.
var a, b, sum;
// Assign value to the variables
b = 25;
// Use arithmetic operator to
// add both numbers
sum = a + b;
Syntax of a function is given below:
// Declare a variable
var num = 15;
// Show the result
// Function invoke
var a, b;
// function is the keyword that instruct the browser to create a function
Comments are part of the code and are ignored during the execution.. We use comments to add the information and suggestions in the code. They increase the readability of code and make the code user-friendly.
In the given example the syntax of comments is given:
// x = 5; It will NOT be executed
These names must start with:
- a dollar sign ($)
- an underscore (_)
- or any letter from the alphabet.