How can closures be used to create private variables in JavaScript?
- By declaring variables with the private keyword inside a function.
- By defining variables in the global scope.
- By using the const keyword to declare variables.
- By declaring variables inside a function that is not accessible from outside the function.
Closures can be used to create private variables in JavaScript by declaring variables inside a function. These variables are not accessible from outside the function, effectively creating encapsulation and data hiding.
Loading...
Related Quiz
- When creating a custom error class in Express.js, it should extend the built-in ______ class.
- What happens if you omit the break statement in a switch statement in JavaScript?
- When installing packages using npm, where are the dependencies listed?
- Which of the following is the correct syntax for destructuring an array in JavaScript?
- The concept of defining a blueprint for the data in the database is known as ________.