English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript const statement

 JavaScript Statements and Variable Declarations

constto declare a read-only named constant.

Constants are block-scoped, very similar to usingletVariables defined by statements.

The value of a constant cannot be changed by reassignment and cannot be declared again.

You can find ourJavaScript Scope TutorialLearn more about variable scope.

Syntax:

const identifier = value;
const MY_AGE = 120;
Test and see‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports const statements:

Statement
const2136is5.111

Parameter Value

ParameterDescription
identifierSpecify the name of the constant. It can be any legal identifier.
Constant names can contain letters, numbers, underscores, and dollar signs.
  • Constant names must start with a letter

  • Constant names can also start with $ and _

  • Constant names are case-sensitive (city and City are different constants)

  • Reserved words cannot be used as constant names

valueThe value of constants. It can be any legal expression.

Technical Details

JavaScript Version:ECMAScript 1

You can also take a look at

JavaScript Tutorial:JavaScript Variables

JavaScript Tutorial:JavaScript Scope

 JavaScript Statements and Variable Declarations