JS Built-ins
StrictModeintermediate

Octal Literals in Strict Mode

Octal Literals in Strict Mode

Strict mode forbids octal literals (e.g. 010 which is 8 in decimal). Use 0o10 (ES6 syntax) instead. The old octal syntax throws a SyntaxError in strict mode.

Challenge: Write testOctalLiteral() that:

  1. Uses eval to run code with old octal syntax (010) in strict mode
  2. Wraps it in try/catch
  3. Returns true if an error is caught, false otherwise
πŸ’‘ Hints (3)
  • β€’ Old octal syntax (010) is forbidden in strict mode
  • β€’ Use 0o10 (ES6) syntax instead
  • β€’ eval() will throw at parse time