Introduction to Variables in JavaScript - Technology & Web designing

Breaking

Friday, 15 May 2020

Introduction to Variables in JavaScript



Variables :

Variables in any programming language are reservation made in the computer's memory to store a value. Variables are denote with a symbol known as variable name. The variable name can then be used to refer to the variable or to change its value. JavaScript provides a number of data types to manage many different types of program data.

Rules for naming variables in JavaScript are standard are in most programming and scripting language :

  1. Variables name always begin with letter, may be alphanumeric i.e. beginning with letter and remaining may be the combination of alphabets and number.
  2. It does not contain any blank space or special symbol except underscore.
  3. The length of variable is limited space special symbol except underscore.
  4. It cannot be a reserved or standard keyword.
  5. Multiple type of declaration is not allowed in JavaScript.
  6. Variable names are case sensitive.

Explicit variables declaration means that a variable has to be declared and initialized first before it is used, whereas in implicit variable declaration, a variable can be used without having any requirement of declaring it first that JavaScript supports explicit as well as implicit declaration of variables. Variables are explicitly declared in JavaScript using the keyword var.

Example :

var a // variable names a has been declared explicitly

a=25 // variable a has been assigned value 25

The two statements can be combined as

var a=25 // variable named a has been declared explicitly

Example :

a=25 // variable named a declared implicitly & assigned value 25

Data types : Every variable used in JavaScript belongs to a specific data type. There are three simple data types available in JavaScript which also known as primitive types that are assigned as type to vauables. These are Number, String and Boolean. Each of these data types allows programmers to store and used different types of data values.

  • Number : Number used to perform arithmetic operations such as addition, subtraction, multiplication and division. Any whole or decimal number that does not appear between quotation marks us considered a number.
  • String : String used to handle text. This data type is simply a series of characters inside quotation marks.
  • Boolean : There are two Boolean values, true and false. These are normally the result of a logical comparison in the code that returns a true/false or yes/no result.

In next post we will learn the detailed about Number, String and Boolean.  

No comments:

Post a Comment

If you have any doubts regarding this please comment or email us.