What is the difference between var and const in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the difference between var and const in JavaScript

var and const is the same.

8th Sep 2018, 6:10 PM
program
program - avatar
2 Answers
+ 5
Const is used to declare a constant => you can't change it after assigning a value. You can read more here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const and here https://dev.to/sarah_chima/var-let-and-const--whats-the-difference-69e.
8th Sep 2018, 6:20 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
- 1
var is a function scope ,but const is block scope like a if(...){ const x=0; } console.log(x); out if scope x is not visible
8th Sep 2018, 6:23 PM
Hovo Shitikyan
Hovo Shitikyan - avatar