You are reviewing a junior developer's code and see the following line var x = 10;. You want to advise them to use a declaration that maintains block scope, which keyword should they use instead of var?
- let
- const
- block
- scope
Instead of var, they should use let to maintain block scope. var has function scope and can lead to unexpected behavior in certain situations, while let declares a variable with block scope, ensuring that it's limited to the block in which it's defined.
Loading...
Related Quiz
- The method _________ is used to parse a JSON response in Fetch API.
- Can arrow functions be used as constructors?
- Which technology was NOT directly influenced by JavaScript's development?
- You're debugging a JavaScript application and notice that a function defined within an object method using an arrow function is not behaving as expected. The "this" keyword is not referring to the object. What could be the reason for this?
-
How can you select all
elements within a specific parent element?