Code For Familias — JS In Brief

[JS In Brief]: var, let, const — what the difference?

Comida For Familias, Inc.
3 min readMar 24, 2022

--

TLDR: [JS In Brief] — This is a series of short Q&A posts dedicated to development. We want to focus your attention on the important aspects of JavaScript. Also, these posts can be useful for interview preparation.

All of the topics presented in this course are just a list with brief explanations. To become a pro you need to study much deeper, and the links at the end of each post will help you with that.

[Q]: var, let, const — what the difference?

This question is related to understanding the Scope and the Hoisting mechanism.

[A]: The main difference is in their scope.

📌 let, const — has block scope (these keywords introduced in ES6), var — function scope;

📌 const — read-only. However, if the value is an array or an object you can change their contents.

If you know that the value of should not change always use `const`.

Example: reassign a value

Example: If the const value is an object or an array, you can change their contents

Example: when accessing a variable before it’s declared

USEFUL MATERIALS:

  1. var vs let vs const in JavaScript — by Tyler McGinnis
  2. Hoisting in Modern JavaScript — let, const, and var by Sukhjinder Arora

This post assumes that you already understand what JavaScript is and the basics. If not, then I recommend reading:
1. How JavaScript Works — by Douglas Crockford;
2. Eloquent JavaScript;
3. The Modern JavaScript Tutorial;
4. JavaScript Guide;

For practice: codewars.com

Author:

Marina Ismailova Software Engineer.

Special thanks for the help in reviewing the article:

Antonio Mendieta CEO at Comida For Familias, Inc. | Jason Hoang Software Engineer.

Subscribe to social networks of Comida For Familias, Inc.:

Website | Facebook | Instagram | LinkedIn | Twitter

JavaScript is very interesting, good luck with your studies!

P.S. I try to get better with you :)

--

--

Comida For Familias, Inc.
Comida For Familias, Inc.

Written by Comida For Familias, Inc.

Leading technological advancement community for food and resources.

No responses yet