You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tech-interview-handbook/front-end/javascript.md

4.5 KiB

JavaScript

Contents

Glossary

  • Closure - TBD
  • Event Loop - The event loop is a single-threaded loop that monitors the call stack and checks if there is any work to be done in the message queue. If the call stack is empty and there are callback functions in the message queue, a message is dequeued and pushed onto the call stack to be executed.
  • Hoisting - TBD
  • Promise - TBD
  • Prototype - TBD
  • This - The this keyword does not refer to the function in which it is used or its scope. It refers to the object on which a function is being executed and depends entirely on the call-site of the function.

Core Language

Variables

Functions

Prototypes and Objects

Async

Reference

Design Patterns

Strict Mode

  1. Strict mode eliminates some JavaScript silent errors by changing them to throw errors.
  2. Strict mode fixes mistakes that make it difficult for JavaScript engines to perform optimizations. Strict mode code can sometimes be made to run faster than identical code that's not strict mode.
  3. Strict mode prohibits some syntax likely to be defined in future versions of ECMAScript.

Converting Mistakes into Errors

  • Prevent accidental creation of global variables.
  • Makes assignments which would otherwise silently fail throw an exception.
  • Makes attempts to delete undeletable properties throw errors.
  • Requires that all properties named in an object literal be unique. Duplicate property names are a syntax error in strict mode.
  • Requires that function parameter names be unique. In normal code the last duplicated argument hides previous identically-named arguments.
  • Forbids setting properties on primitive values in ES6. Without strict mode, setting properties is simply ignored (no-op), with strict mode, however, a TypeError is thrown.

Simplifying Variable Uses

  • Prohibits with.
  • eval of strict mode code does not introduce new variables into the surrounding scope.
  • Forbids deleting plain variables. delete name in strict mode is a syntax error: var x; delete x; // !!! syntax error.

Paving the way for future ECMAScript versions

  • Future ECMAScript versions will likely introduce new syntax, and strict mode in ECMAScript 5 applies some restrictions to ease the transition. It will be easier to make some changes if the foundations of those changes are prohibited in strict mode.
  • First, in strict mode a short list of identifiers become reserved keywords. These words are implements, interface, let, package, private, protected, public, static, and yield. In strict mode, then, you can't name or use variables or arguments with these names.
  • Second, strict mode prohibits function statements not at the top level of a script or function.