Câu hỏi phỏng vấn Javascript
Câu hỏi

What is strict mode in javascript?

Câu trả lời

Strict mode in JavaScript is a feature that allows you to place a program, or a function, in a "strict" operating context. This strict context prevents certain actions from being taken and throws more exceptions. It was introduced in ECMAScript 5 and serves several functions:

  1. Catches Common Coding Mistakes: It turns some silent errors into throw errors, helping developers to identify issues early in the development process. For example, in strict mode, trying to assign a value to an undeclared variable will throw an error[1][2][3][4].

  2. Prevents or Throws Errors for Unsafe Actions: Actions that are considered unsafe, such as gaining access to the global object, are prevented or will throw errors. For instance, in strict mode, this is undefined in functions that are not methods or constructors, whereas in non-strict mode, this would default to the global object[2].

  3. Disallows Syntax Likely to be Defined in Future ECMAScript Versions: It prohibits some syntax which is likely to be defined in future versions of ECMAScript, thus avoiding potential issues with future compatibility[1][2].

  4. Eliminates with Statements: The with statement is not allowed in strict mode because it can lead to unpredictable results and it's difficult for JavaScript engines to optimize[1][6].

  5. Simplifies Variable Use: It simplifies how variable names map to particular variable definitions in the code, which can make it easier for JavaScript engines to perform optimizations[1].

  6. Makes eval() Safer: Strict mode makes eval() safer by not introducing new variables into the surro...

junior

junior

Gợi ý câu hỏi phỏng vấn

senior

Does JavaScript have a map function to iterate over an object properties?

senior

Explain what is Hoisting in Javascript

expert

Does JavaScript pass by references or pass by values?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào