How to prevent duplicate JavaScript Variables Declaration?

JavascriptWeb DevelopmentFront End Technology

To prevent duplicate variable declaration in JavaScript, wrap your variable declaration with a function expression:

   var rank = 1;

The above code prevents your variable from other variables and functions. This won’t effect other global variables outside the function.

You variable rank won’t be visible outside the function, so whatever code you write for the variable should be inside the function.

Updated on 07-Jan-2020 06:54:56