How can you create a private variable in JavaScript?
a) Using closures
b) Using
var
outside a functionc) Using
this
keywordd) Using
let
outside a functionAnswer:
a) Using closures
Explanation:
Private variables in JavaScript can be created using closures. A closure is an inner function that has access to the outer function’s variables, even after the outer function has returned. This allows private variables to be encapsulated within a function.