Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript
web development
frontend
community creator

What is the const keyword in JavaScript?

Natalia Bubiak

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

var, let, and const are probably the first words you hear about while learning JavaScript. Since the let keyword has been already explained in this Edpresso shot, and var doesn’t deserve a separate article yet, let’s find out what const is:

const

  • const is a JavaScript keyword introduced by ES6 that doesn’t have a previous equivalent.
let x = 10;

const x = 10; //This is not possible.
  • const creates block-scoped and read-only reference that cannot be reassigned.
const x = 10;
x = 15;
console.log(x); //This is will throw an error because
//x is read-only
  • It is a good practice to write const identifiers in all-uppercase (to vary them from let variables).
const TEMP_X = 10;
  • A value assigned to the const keyword has to be initialized immediately. A const keyword without an assigned value will cause a syntax error.
const X; //This is not possible.

RELATED TAGS

javascript
web development
frontend
community creator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring