+ 1
When we use const variable?
explain with a example
9 Antworten
+ 4
ASJAD🔹
const is not similar to let. You can change the value of let but you can't change the value of const.
Sajid Ali
When you don't want to change the value of a variable then you should use const.
For example:
const x = 10
let y = 20
y = 30 //it will not give error
x = 20 //it will give error
console.log(y)
console.log(x)
Try above code in Code Playground and see the difference.
+ 2
Actually, it is not variable it's constant value and you can use them to declare higher order function * aka lambda some Times it is called "arrow function", none mutable values ( which you no longer dare to change their value)
+ 2
ASJAD🔹
You can say var is similar to let but let is blocked scope means we cannot access the value of let outside the block. You can try below example in Code Playground
{
var x = 30
let y = 20
}
console.log(x)
console.log(y)// gives error
+ 1
ASJAD🔹 bro.. local variable can not be access from outside block
+ 1
I Am AJ ! It mean that,,
Const variable can not be override the value,,, in respect of local block and global block
And
Let variable can be override the value in respect of local block and global block