How to declare a block-scoped variable in JavaScript?
- var keyword
- const keyword
- let keyword
- block keyword
In JavaScript, you can declare a block-scoped variable using the let keyword. Variables declared with let are limited in scope to the block, statement, or expression in which they are defined. This helps prevent unintended variable hoisting and allows you to create variables with localized scope within functions or blocks. var is function-scoped, and const is used to declare constants. block is not a valid keyword for variable declaration.
Loading...
Related Quiz
- You've encountered a "Callback Hell" in a project you've inherited. What could be a strategic approach to refactor and manage the nested callbacks for better readability and maintainability?
- If you want to convert a JavaScript object to a string in the Fetch API, you should use the _________ method.
- What is the main difference between function declaration and function expression in JavaScript?
- What happens when a function declaration and a var variable are hoisted in the same scope?
- Which method is commonly used to change the text content of an HTML element using JavaScript?