The correct syntax to declare a constant named PI with a value of 3.14 is const PI = 3.14;, where const ensures PI remains constant throughout the program.
4.
What happens if you try to reassign a value to a constant declared using const?
Block scope in JavaScript means that variables declared with let or const are accessible only within the block they are defined in, enhancing code clarity.
The output will be 10. Although x is declared again within the block, it creates a new block-scoped variable, so the outer x remains unchanged with a value of 10.
7.
Which of the following statements is true about constants declared using const?
Constants declared using const in JavaScript are immutable, meaning their value cannot be changed once initialized, making them useful for defining fixed values.
8.
What is the primary advantage of using block scope in JavaScript?
Block scope in JavaScript primarily helps in avoiding global variables, reducing the risk of variable naming conflicts and unintentional changes to global state.
9.
Which of the following is NOT an example of a block in JavaScript?
In JavaScript, object literals are not considered blocks, whereas function bodies, if statement bodies, and loop bodies are examples of blocks with block scope.