This website uses cookies to enhance the user experience

JavaScript Interview Questions

23 Questions
JavaScript

JavaScript

Web DevelopmentFrontendBackend

Question 19

What is strict mode in JavaScript?

Answer:

Strict mode is a way to opt into a restricted variant of JavaScript, which catches common coding errors and unsafe actions such as defining global variables. It can be enabled by adding 'use strict'; at the beginning of a script or function. Strict mode helps in writing secure JavaScript code by eliminating silent errors, improving performance, and preventing certain actions like the use of undeclared variables.

Here is an example demonstrating strict mode:

'use strict';

// This will throw an error because x is not declared
x = 3.14;

// This will throw an error because duplicate parameter names are not allowed
function sum(a, a, c) {
    return a + a + c; // Duplicate parameter name not allowed in strict mode
}

// This will throw an error because deleting a function is not allowed
function myFunction() {}
delete myFunction;

In this example, strict mode catches errors that would otherwise be ignored in non-strict mode, such as using undeclared variables, duplicate function parameters, and deleting a function.

Recent job openings

South Africa, Claremont, Western Cape

Remote

Full-time

posted 4 days ago

India

Remote

Full-time

JavaScript

JavaScript

TypeScript

TypeScript

+4

posted 4 days ago

India, Noida, UP

Remote

Full-time

Python

Python

JavaScript

JavaScript

+5

posted 4 days ago

India

Remote

Contract

JavaScript

JavaScript

TypeScript

TypeScript

+4

posted 4 days ago

Philippines, Mandaluyong City, Metro Manila

Remote

JavaScript

JavaScript

SQL

SQL

+8

posted 4 days ago