Search blog

Sunday, April 15, 2018

Why NOT to Use var and Instead Use let or const in JavaScript

Consider the following example code:


You can note that the value of var a has changed due to the assignment within the block scope of the if statement, while the value of let b & const c value have remained unaffected.

So, the way let & const works is the way most programming languages work.

var is kind of weird, it’s one of the things a lot of people didn’t like about JavaScript. It causes security risk and confusion and hence it’s better to avoid it.

No comments:

Post a Comment

Thank you for your Feedback!
www.evagabond.me

Top 5 Posts (Weekly)