Which of the following is a suitable method to prevent variable leakage in the global scope?

  • Using the var keyword to declare variables.
  • Using immediately-invoked function expressions (IIFE).
  • Using global variables exclusively.
  • Using let and const keywords to declare variables.
Using immediately-invoked function expressions (IIFE) is a common technique to prevent variable leakage into the global scope. It encapsulates variables within a function scope, avoiding global pollution. The other options do not address this concern effectively.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *