JS Built-ins
StrictModeintermediate

Deleting Variables in Strict Mode

Deleting Variables in Strict Mode

Strict mode forbids using delete on variables, function names, or function parameters. delete myVar throws a SyntaxError in strict mode.

Challenge: Write testDeleteVariable() that:

  1. Uses eval to run code that deletes a variable in strict mode
  2. Wraps it in try/catch
  3. Returns true if an error is caught, false otherwise
πŸ’‘ Hints (3)
  • β€’ delete on variables is forbidden in strict mode
  • β€’ delete works on object properties, but not variable declarations
  • β€’ Use eval() to trigger the error