The const keyword

Using the const keyword, you can create variables that cannot change their values (hence they're  called constants) once they're initialized, that is, you cannot reinitialize them with another value later in your code.

If you try to reinitialize a const variable, a read-only exception is thrown. Furthermore, you cannot just declare and not initialize a const variable. It'll also throw an exception.

For instance, you might want your JavaScript to crash if someone tries to change a particular constant, say pi, in your calculator. Here's how to achieve that:

const pi = 3.141;
pi = 4; // not possible in this universe, or in other terms,
// throws Read-only error
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.140.134