Variables in JavaScript:

Variables are nothing but a container to store data. Variables hold the data for some operation and we can use it later in our programming.

To declare a variable you must use “var” keyword before that variable name.

Here is a simple example to create variables and doing the addition of those variables

 Example:

In above example variable “a” hold value “5”. Variables are also used to hold expression like above example variable “z” is holding the “a
+b” addition of two variables.

Many Variables in One Line:

You can declare variables in a single line means one statement with many variable declarations and also you can pass string value to a variable. String should be always declared in “ ” (double quotes). You can understand it by following variable declaration:

Example:

var a=5, b=6, z;

var name=”Angle” phone=9823924;

Note:

One thing also you should know that “var” keyword is only use for declaring variable. After declaring variable you can use them by their name means you don’t have to always write “var” keyword before variable .

Example:

In following example we are using both integer and string type declaration

List of JavaScript Reserved Words:

Below is a list of predefined or reserved JavaScript words and they can not be used as a variable name, function, method etc.

List of Reserved Keywords
          abstract             else           instanceof            switch
          boolean             enum           int            synchronized
          creak             export           interface            this
          byte             extend           long            throw
          case             false           native            throws
          catch             final           new            transient
          char             finally           null            true
          class             float           package            Try
          const             for           private            typeof
          continue             function           protected            var
          debugger             goto           public            void
          default             if           return            volatile
          delete             implements           short            while
          do             import           static            with
          double            in           super  

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *