Website Development Online Courses

what are variables in javascript

Like any other programming language JavaScript also have variables. It stores the value which can be used later.

Example below

  • Var is the keyword which tells JavaScript you are declaring variable
  • x is the name of the variable
  • = is the operator that tells JavaScript a value is coming next
  • 25 is the value for the variable to store

There is another way of writing it

You can also declare multiple variables with the same var keyword as follows

You should not re-declare the same variable twice.
For example
The above example will print 25 it will overwrite the value Hello world So it is better to structure variable name which you are going to use in your project.

Naming Variables

  1. Name of the variable must start with a letter (a to z or A to Z), underscore (_), or dollar ($) sign.
  2. After the first letter, we can use digits (0 to 9), for example, john1.
  3. JavaScript variable are case sensitive for example for example x and X are different variable.

JavaScript Reserved words

The list of reserved words is given in the following table. They cannot be used as JavaScript variables.

abstract else instanceof switch
boolean enum int synchronized
break export interface this
byte extends 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

Watch the tutorial

Leave a Reply

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