JavaScript Variables :
Variables serve as fundamental elements in any programming language. In JavaScript, they function to store values that can be reused. Allocation of values to variables is achieved through the use of the assignment operator ("=").
Key points to take in notice while declaring variables in java script .
- Variables must have unique names.
- These are case-sensitive
- Can only begin with a letter, underscore(“_”) or “$” symbol.
- It can contain letters, numbers, underscore, or “$” symbol.
- A variable name cannot be a reserved keyword.
Variable declaration Examples :
Variable declaration with var
you can reassign var variable :
you can redeclare var variable :
var variable is not limited to block hence it does not have block scope . var variables are function scope or global scope.
variable declaration with let
you can reassign let variable :
you can not redeclare let variable :
let variables are limited to block in which they are defined . it have block scope :
variable declaration with const
const variable can not be reassigned once assigned.
you can not redeclare const variables
const variables are block scoped it means you can not access the variable outside the block .
In next blog post we will discuss about string functions , functions(methods) stay tuned
Comments
Post a Comment