Constant 1/3
What are Constants?
Constants are created just like the var
and let
. We use the const
keyword for initializing constants, for example.
9
1
2
const NUMBER = 58;
console.log(NUMBER);
12const NUMBER = 58; console.log(NUMBER);
Variables declared with const
are very much similar to the variables declared with the let
keyword, but the only difference is that we cannot reassign values to the variables declared with the const
keyword.
9
1
2
3
const PI = 3.141592653589793;
PI = 3.14; // error
console.log(PI);
123const PI = 3.141592653589793; PI = 3.14; // error console.log(PI);
Oppgave
Swipe to start coding
Declare a variable by using the const
keyword with the identifier FIXED
and assign the value 10 to it also display the value on the console.
Løsning
9
1
2
const FIXED=10;
console.log(FIXED);
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 3. Kapittel 9
single
9
1
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår