In JavaScript, const means "constant" and is a keyword used to declare one or more constants. They must be initialized when declaring, and the value cannot be modified after initialization. If the value of the constant is changed, it will Throws a type error, the syntax is "const constant name = constant value;".
How to quickly get started with VUE3.0: Enter
the operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
ES2015 (ES6) has added two important JavaScript keywords: let and const.
Variables declared by let are only valid within the code block where the let command is located.
const declares a read-only constant. Once declared, the value of the constant cannot be changed.
Used to declare one or more constants. They must be initialized when declaring, and the value cannot be modified after initialization.
Const defined constants are similar to variables defined using let:
both are block-level scopes
and cannot be compared with other objects in the scope in which they are located.
There are two differences between
variables or functions with the same name
Constants declared with const must be initialized, while variables declared with let are not
const. The value of a constant defined by let cannot be modified by reassignment, nor can it be declared again. The variable values defined by let can be modified.
Examples are as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <h2>JavaScript const</h2> <p>const is used to declare one or more constants. They must be initialized when declaring, and the value cannot be modified after initialization. </p> <p id="demo"></p> <script> try { const PI = 3.141592653589793; PI = 3.14; } catch (err) { document.getElementById("demo").innerHTML = err; } </script> </body> </html>
Output results: