+ 1
[Exact]Difference between Javascript variables!?
I'd know javascript,(var , let , const)But these types of variables keep me a bit confused...so I want to that what is the difference between each other and in which purpose they are used,and is their any (important) thing that I don't know about these ?
9 Antworten
+ 7
Here read this
"Var, Let, and Const – What's the Difference?" https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/
I hope you find your answer .If not ignore it.Thanks😁🤗
+ 4
Dark Stream[📝📚📝😇] Welcome 🤗
+ 4
VAR
+ are the oldest way to declare variable.
+ are hoisted
+ are function scoped
+ without declaring a variable, you'll get it as a global var, if not using "strict mode" (else you raise an error)
LET, CONST
+ are newest way to declare variable
+ are not hoisted
+ are block scoped
+ LET is quite equivalent to VAR, CONST can only be assigned once (constant mean that they never change)
HOISTED:
mean that even if declaration occurs later in code, you could use variable... if not (let, const), you get an error if variable was not declared before...
+ 3
Thank you, I just Found the perfect simple answer
+ 3
Exampel code :
1. "var"
|
V
var first_code = 1
var second_code = 2
alert(first_code + second_code)
2. "let"
|
V
for(let i = 0;i < 6;i++){
return i
}
3. "const"
|
V
const first_code = 1
/* can be "first_code = 1" */
alert(first_code)
+ 2
Thank you too
+ 2
Ok thank you 😇
+ 2
Your welcome...