Variables In JS
What are we going to learn in this video?
- What are variables?
- What are different data types in JS?
- What is typeof operator
What are variables??
Variables are the one which holds a value and that value can be changed and used in other places.
Here one is the variable name and 1 is the value it holds.
var one = 1;
one = "one";
In What is JS video, I said that JS is a weakly typed variable. What that means is, in the above statement, variable is assigned a value of data type of number and in run time 1 is replaced by "one" which is completely different data type(string).
Many of the languages won’t allow this but JS since it is dynamic and weakly typed it allows it.
Data Types
There are two broad types of data types in JS,
1. Primitive
- Number
- String
- Boolean
- null
- undefined
2. Non Primitive
- Objects
- Array
Const and let
Till ES5, there was no block level scope in Javascript,
What is block level scope??
if {
// This is a block
}
for () {
//This is a block
}
Const and let are created in ES6 to support block level scope.
Typeof
Type of is one of an operator in Javascript. Typeof is used to find the type of the variable.
const city = 'bengaluru';
typeof city // string
const num = 1000;
typeof num // number
const isValid = true;
typeof isValid // boolean
Variables
By hentry martin
Variables
- 227