Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 14.9 — Strict Mode and Language Quirks
JavaScript · Example 2 of 3

Syntax strict mode forbids, and arguments and eval changes

These are compile-time errors: in a real file, one of them would stop the whole script before any line ran. The Function constructor lets us show each one separately.

Strict mode, switched on by "use strict" and automatically on in modules and classes, turns silent mistakes into errors, removes a few confusing features and makes this safer; the rest of JavaScript's odd legacy behaviours stay in the language forever, so you learn to recognise and avoid them.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 5 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Predict and explain the output of "use strict"; function show() { return typeof this; } console.log(show(), show.call(7));.

02

This sloppy code has a typo that strict mode would catch. Add the directive, run it, and fix the bug: let score = 0; function addPoint() { scor = score + 1; } addPoint(); console.log(score);

Explain it without notes

01

What is strict mode, how do you enable it, and where is it on automatically?

02

List four behaviours that change in strict mode.

03

Why does this differ between sloppy and strict functions called without an object?

04

Name some legacy quirks strict mode doesn't fix, and why they can't be fixed.

Syntax strict mode forbids, and arguments and eval changes

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

SyntaxError: Strict mode code may not include a with statement
SyntaxError: Octal literals are not allowed in strict mode.
SyntaxError: Unexpected eval or arguments in strict mode
SyntaxError: Unexpected strict mode reserved word
SyntaxError: Delete of an unqualified identifier in strict mode.
SyntaxError: Duplicate parameter name not allowed in this context
arguments linked: 2 strict: 1
eval adds a variable: number strict: undefined