0
0
Javascriptprogramming~5 mins

Variable declaration using const in Javascript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does const mean in JavaScript?

const declares a variable that cannot be reassigned after its initial value is set.

Click to reveal answer
beginner
Can you change the value of a const variable after it is declared?

No, you cannot reassign a new value to a const variable once it is declared.

Click to reveal answer
beginner
Is it possible to declare a const variable without initializing it?

No, const variables must be initialized when declared.

Click to reveal answer
intermediate
Does const make objects or arrays immutable?

No, const prevents reassignment of the variable, but the contents of objects or arrays can still be changed.

Click to reveal answer
beginner
Example: What will happen if you run this code?<br><pre>const x = 5;<br>x = 10;</pre>

This will cause an error because x is declared with const and cannot be reassigned.

Click to reveal answer
What happens if you try to reassign a const variable?
AIt ignores the reassignment
BIt changes the value successfully
CIt converts the variable to let
DIt causes an error
Can you declare a const variable without giving it a value?
ANo, it must be initialized immediately
BYes, and assign later
CYes, but only inside functions
DOnly if it is a number
Which of these is true about const and objects?
AYou can change properties but cannot reassign the object
BYou can neither reassign nor change properties
CYou can reassign the object but not change properties
DYou cannot change properties of a <code>const</code> object
Which keyword declares a variable that cannot be reassigned?
Avar
Bconst
Clet
Dstatic
What will this code output?<br>
const name = 'Alice';<br>console.log(name);
AError
Bundefined
CAlice
Dnull
Explain how const works for variable declaration in JavaScript.
Think about what you can and cannot do after declaring with const.
You got /3 concepts.
    Describe the difference between const and let in JavaScript.
    Focus on reassignment and scope.
    You got /3 concepts.