The following code is legal and executes without any warning:
There are several ways to avoid the issue:
- use strict
By adding a
'use strict'; statement at the beginning of the function, you will get an error thrown:
- JSHINT and JSLINT
Both Linters will throw a warning and let you know that
x is already defined.