Common Errors Caught by JavaScript Strict Mode

See the most common mistakes that JavaScript strict mode catches, including undeclared variables, read-only assignments, duplicate parameters, and more.

5 min read

JavaScript strict mode errors are mistakes that strict mode turns into clear failures. Without strict mode, some of these mistakes are ignored or behave in confusing ways.

This article shows the common errors beginners are most likely to meet.

Quick Reference

MistakeStrict Mode Result
Assigning to an undeclared variableReferenceError
Writing to a read-only propertyTypeError
Deleting a plain variableSyntaxError
Duplicate parameter namesSyntaxError
Legacy octal literalSyntaxError
with statementSyntaxError
Plain function thisundefined

Use this table as a map. The sections below explain the errors that matter most in beginner code.

Mistake 1: Undeclared Variables

Forgetting a declaration keyword is one of the most common strict-mode catches.

javascriptjavascript
"use strict";
 
function setScore() {
  score = 100;
}
 
setScore();

This throws a ReferenceError because score was never declared. Declare the variable before assigning to it.

Mistake 2: Writing to Read-Only Properties

Strict mode throws when you try to write to a property that cannot be changed.

javascriptjavascript
"use strict";
 
const config = {};
Object.defineProperty(config, "apiKey", {
  value: "abc123",
  writable: false,
});
 
config.apiKey = "xyz789";

The final line throws a TypeError. The property exists, but it was defined as not writable.

This is better than silent failure because you find the mistake immediately.

Mistake 3: Deleting Variables

Strict mode does not allow deleting a plain variable name.

javascriptjavascript
"use strict";
 
let count = 10;
delete count;

This is a SyntaxError. Use delete for object properties, not local variables.

For example, deleting an object property can be valid if the property is configurable. Deleting a local variable is not.

Mistake 4: Duplicate Parameter Names

Strict mode rejects functions that repeat a parameter name.

javascriptjavascript
"use strict";
 
function add(value, value) {
  return value + value;
}

This is a SyntaxError before the function runs. The fix is to give each parameter a unique name.

Duplicate names hide values and make function calls hard to reason about.

Mistake 5: Legacy Octal Literals

Old JavaScript allowed number literals with a leading zero in some non-strict scripts. Strict mode rejects that legacy form.

javascriptjavascript
"use strict";
 
console.log(0123);

This is a SyntaxError. If you intentionally want octal, use the modern zero-o prefix instead.

Mistake 6: with Statements

The with statement changes how variable lookup works, which makes code hard to understand and optimize. Strict mode forbids it.

javascriptjavascript
"use strict";
 
const user = { name: "Alice" };
with (user) {
  console.log(name);
}

This is a SyntaxError. Write the property access directly instead, such as user.name.

Mistake 7: Plain Function this

Strict mode changes plain function calls so this stays undefined instead of falling back to the global object.

javascriptjavascript
"use strict";
 
function showThis() {
  console.log(this);
}
 
showThis();

The output is undefined. This helps prevent accidental writes to the global object.

What Strict Mode Does Not Catch

Strict mode is useful, but it is not a full bug detector. It does not know that your formula is wrong, your API URL is misspelled, or your UI state has the wrong value.

Use strict mode with a good debugging process and a linter. Strict mode catches language mistakes; your tests and tools catch the rest.

Once your code runs in strict mode, follow consistent variable naming conventions and a practical JavaScript code style guide.

Rune AI

Rune AI

Key Insights

  • JavaScript strict mode errors are often mistakes that sloppy mode ignores.
  • Assigning to an undeclared variable throws a ReferenceError.
  • Writing to read-only or getter-only properties throws a TypeError.
  • Deleting plain variables is a SyntaxError in strict mode.
  • Duplicate parameter names and with statements are rejected.
RunePowered by Rune AI

Frequently Asked Questions

Will strict mode catch all JavaScript bugs?

No. It catches specific language mistakes, not general logic bugs.

Can strict mode break old code?

Yes. Old code that relied on sloppy-mode behavior can start throwing errors.

Should I use a linter with strict mode?

Yes. A linter can catch many strict-mode problems before runtime.

Conclusion

Strict mode catches mistakes that normal scripts may ignore, especially accidental globals, invalid deletes, duplicate parameters, unsafe property writes, and old syntax such as with statements.