JavaScript
JavaScript is fun and powerful programming language for
front end web developing. JavaScript is used most of the popular web
applications. Eg : google Map , Gmail , PayPal , LinkedIn …… etc.
JavaScript Variable Type
JavaScript is loosely type language. In variable declaration
we don’t need to define any datatype like integer, string , Boolean. We can
declare all type of variable not only
integer, Boolean , string but also objects just using ‘var’ or ‘let’ or ‘const’ keywords.
Later we’ll discuss about different between these above
mentioned keyword. But commonly we use var keyword to declare variable.
Variable declaration
When declare a variable without initializing a value then it
will automatically take undefined or
null value. And also we can define multiple variable with same var keyword.
Variable naming concerns.
- JavaScript is case – sensitive. eg : Age , age are two different variable.
- We can’t use JavaScript key word eg: int , let , break , class , export , supper , final.
- Variable name should not start with numbers(0-9) , must begin with a letter or underscore or dollar sign
Eg: 1name
== invalid
_12name
is valid
Variable scope
In javascript there are two types of variable scope
1.Global Variable
2.Local Variable
Global variable
These variables are define out of the function scope. All
global variables are belongs to the window object. For best practice these
global variables are define in uppercase letters.
Global
variables can be got from anywhere.
If we declare a variable without ‘var’ keyword it will
automatically assign as global variable.

Local variable
Local variables are define inside the function. These
variables only accessible within that function.
Var , let , const
- Var keyword used to define a variable within the functional scope. Let and const keyword used to define a variable within the block scope.
- Var & let variables can change their value but const variables can’t change.
- Const variable can’t be declared without initialization but var and let not like that.
Comments
Post a Comment