What is JavaScript strict mode?
A
A faster version of JavaScript B
A mode that catches common coding errors C
A new version of ECMAScript D
A CSS feature
Analysis & Theory
Strict mode makes JavaScript more secure and catches common coding mistakes.
How do you enable strict mode?
A
"enable strict"; B
#use strict; C
"use strict"; D
//use strict
Analysis & Theory
You enable strict mode by writing `'use strict';` at the top of a script or function.
Which of the following will throw an error in strict mode?
A
x = 10; B
let x = 10; C
console.log('Hello'); D
function test() {}
Analysis & Theory
In strict mode, assigning to undeclared variables like `x = 10;` causes a `ReferenceError`.
What happens if you assign to a read-only property in strict mode?
A
It fails silently B
It assigns anyway C
It throws a TypeError D
It removes the property
Analysis & Theory
In strict mode, writing to a read-only property causes a `TypeError`.
Can you use `with` statements in strict mode?
A
Yes B
Only inside functions C
No D
Only in modern browsers
Analysis & Theory
`with` is not allowed in strict mode as it makes code unpredictable.
What will this code do in strict mode?
```js
'use strict';
delete Object.prototype;
```
A
Deletes the property B
Fails silently C
Throws a SyntaxError D
Throws a TypeError
Analysis & Theory
In strict mode, deleting undeletable properties throws a `TypeError`.
Which is true about strict mode?
A
It disables all functions B
It prevents variable hoisting C
It simplifies debugging and improves performance D
It changes how browsers render pages
Analysis & Theory
Strict mode helps catch errors early and simplifies debugging.
Where can strict mode be applied?
A
Only in external scripts B
Only in functions C
Entire scripts or individual functions D
Only in the browser
Analysis & Theory
Strict mode can be applied globally or inside individual functions.
What error will this cause in strict mode?
```js
function f(a, a) {}
```
A
TypeError B
SyntaxError C
ReferenceError D
No error
Analysis & Theory
Strict mode doesn't allow duplicate parameter names — causes a `SyntaxError`.
Why is strict mode useful?
A
It allows old syntax B
It makes code compatible with HTML C
It prevents silent errors and enforces better practices D
It disables all global variables
Analysis & Theory
Strict mode helps you write cleaner, safer, and more predictable code.