[Exact]Difference between Javascript variables!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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 ?

17th Mar 2021, 10:51 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
9 Answers
+ 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😁🤗
17th Mar 2021, 10:55 AM
!Derrickee
!Derrickee - avatar
17th Mar 2021, 11:10 AM
!Derrickee
!Derrickee - avatar
+ 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...
17th Mar 2021, 11:15 AM
visph
visph - avatar
+ 3
Thank you, I just Found the perfect simple answer
17th Mar 2021, 11:09 AM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 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)
17th Mar 2021, 1:17 PM
Carbon dioxide
Carbon dioxide - avatar
+ 2
Thank you too
17th Mar 2021, 12:05 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 2
Ok thank you 😇
17th Mar 2021, 1:54 PM
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ
•Đคяк รтяεคм 𝅘𝅥𝅮 ᴺ•ᵀ•ᴬˢᵘʳᵃᵖᵖᵘˡᶦ - avatar
+ 2
Your welcome...
17th Mar 2021, 1:55 PM
Carbon dioxide
Carbon dioxide - avatar