CARVIEW |
Select Language
HTTP/2 307
date: Sun, 12 Oct 2025 17:05:41 GMT
content-type: text/html
content-length: 63
location: https://how.dev/answers/what-is-the-const-keyword-in-javascript
cf-ray: 98d82ef6ac4fc16d-BLR
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-robots-tag: all
x-nextjs-cache: MISS
x-cloud-trace-context: 2d4c75f4f8cab2d49be4a979af1bd47a;o=1
via: 1.1 google
alt-svc: h3=":443"; ma=86400
cf-cache-status: MISS
set-cookie: __cf_bm=_8il5Ba4kicmG9OksutslUuGmRZ1EJePGm_0qpiMf7E-1760288741-1.0.1.1-mzeBj52tL5EZHA0o3.T49rAuXSE.IeYmDAYm45h2im3Py.m14WDZ7T61Xh7m2CH_myydEg9jCqlRFB.ydC9AmlyFBntlAeGCPeOPoAhL2Io; path=/; expires=Sun, 12-Oct-25 17:35:41 GMT; domain=.educative.io; HttpOnly; Secure; SameSite=None
vary: Accept-Encoding
strict-transport-security: max-age=31536000; includeSubDomains; preload
server: cloudflare
HTTP/2 200
cache-control: public, max-age=300, stale-while-revalidate=604800
referrer-policy: strict-origin-when-cross-origin
x-app-version: v251008-h-251010-1202
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
x-app-type: Learn
x-middleware-rewrite: /answers/howdev/what-is-the-const-keyword-in-javascript
x-nextjs-cache: MISS
etag: W/"130dqx6mk3j6m5p"
content-type: text/html; charset=utf-8
x-cloud-trace-context: e66a48006716fa6e2a5ce2ee0b02b34e
date: Sun, 12 Oct 2025 17:05:42 GMT
server: Google Frontend
via: 1.1 google
vary: Accept-Encoding
content-encoding: gzip
x-cache-status: miss
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
What is the const keyword in JavaScript?
What is the const keyword in JavaScript?
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 Answer, 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 fromlet
variables).
const TEMP_X = 10;
- A value assigned to the
const
keyword has to be initialized immediately. Aconst
keyword without an assigned value will cause a syntax error.
const X; //This is not possible.
Relevant Answers
Explore Courses
Free Resources