Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Browser Support

Full support for the const keyword started from the following browser versions:

  • Internet Explorer: Not supported in versions 10 or earlier.
  • Other browsers: Supported in all modern browsers since their initial releases.

IMG_4156

Assigned when Declared

In JavaScript, const variables, including arrays, must be assigned a value at the time of declaration. Declaring an array with const without initializing it will cause a syntax error.

Example

This approach will not function.

const cars;
cars = [“Saab”“Volvo”“BMW”];

Arrays declared with var can be initialized later and used before their declaration due to hoisting.

Example

This is acceptable.

cars = [“Saab”“Volvo”“BMW”];
var cars;