Is sololearn wrong to use var instead of Const or let during creation of a new object | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is sololearn wrong to use var instead of Const or let during creation of a new object

function Human(name, age, race) { this.name = name; this.age = age; this.race = race; } var X = new Human('Alex', 20, 'African'); Const X = new Human('Alex',20,'African'); Let X = new Human ('Alex',20,'African'); console.log(X.name); //Which of the three is correct?//

15th Mar 2023, 12:28 PM
Alex Wairegi
Alex Wairegi - avatar
3 Answers
15th Mar 2023, 12:42 PM
Yasin Rahnaward
Yasin Rahnaward - avatar
+ 6
var is the old way of declaring variables. There is still a lot of old Javascript code out there, written before const and let were added to the language. So you need to know how it works, what are its limitations and gotcha's. But when writing new code, you really should use let and const. https://javascript.info/variables
15th Mar 2023, 12:55 PM
Tibor Santa
Tibor Santa - avatar
0
Yeap. Many of the solutions and lessons are wrong/bad code and I'm starting to feel like this site is hindering my progress.
17th Mar 2023, 11:37 PM
GMcLDev