Mark As Completed Discussion

We know that in today's age, everybody is on the internet. If you're reading this, you've made it onto the world wide web, and are running the wonderful language of Javascript.

Created in 1995, Javascript's evolution until now couldn't have been predicted. Brendan Eich had sought out to spice up static webpages, never expecting giant powerhouses like Google and Facebook to use the language in such potent ways.

static_assets

Not only are billion dollar businesses being built on Javascript, but the versatile language has also produced some of the most popular frameworks out there:

  1. React.js
  2. jQuery
  3. d3.js
  4. Ember
  5. Angular
  6. Next.js
  7. Babel

This guide will take you through some common Javascript interview questions testing your knowledge on syntax and JS features. Press Next to start!

Build your intuition. Is this statement true or false?

In JavaScript, the conversion between two different built-in types is deemed coercion.

Press true if you believe the statement is correct, or false otherwise.

Coercion comes in two forms in the JS language: explicit and implicit.

Here's an example of explicit coercion:

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Click the correct answer from the options.

What is the typeof operator?

Click the option that best answers the question.

  • An operator that can examine a value and tell you what type it is
  • The way to tell how large a font size is
  • typeof does not exist in Javascript
  • I'm not sure

JavaScript provides a typeof operator that can examine a value and tell you what type it is:

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Is this statement true or false?

If you needed to compare two values, and you care that they are of the same type, you would use the === operator.

Press true if you believe the statement is correct, or false otherwise.

JavaScript has both strict and type-converting comparisons:

  • Strict comparison (using 3 equal signs like ===) checks for value equality without allowing for coercion
  • Abstract comparison (e.g. ==) checks for value equality with coercion allowed
Info Screen

Here are some simple equality rules:

  • If either value (aka side) in a comparison could be the true or false value, avoid == and use ===.
  • If either value in a comparison could be of these specific values (0, , or [] -- empty array), avoid == and use ===.
  • In all other cases, you're safe to use ==. Not only is it safe, but in many cases it simplifies your code in a way that improves readability.
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Click the correct answer from the options.

The term scope in JavaScript is defined as?

Click the option that best answers the question.

  • A brand of mouthwash that competes wtih Listerine
  • A collection of variables as well as the rules for how those variables are accessed by name
  • Everything that can be accessed by a variable
  • A data structure in Javascript

In JavaScript, each function gets its own scope. A function's scope is a collection of variables, as well as the accessibility of these variables inside and outside of the function. Only code lexically residing within the function's block can access that function's scoped variables.

Info Screen

A variable name has to be unique within the same scope. Additionally, a scope may also be nested inside another scope. If one scope is nested inside another, code inside the innermost scope can access variables from either scope.

In addition to letting you create declarations for variables at the function level, ES6 allows you declare variables that belong to individual blocks (pairs of { .. }), using the let keyword.

Source

Let's test your knowledge. Fill in the missing part by typing it in.

A ___ is a function that is passed to another function as an argument.

Write the missing line below.

A callback is a function that is passed to another function as an argument. It is then executed after some operation has been completed. The following is an example of a simple callback function that logs to the console after some operations have been completed.

Source

https://coderbyte.com/algorithm/10-common-javascript-interview-questions

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Is this statement true or false?

Strict Mode is a new feature in ECMAScript 5 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.

True or False?
JAVASCRIPT
1// Non-strict code...
2
3(function(){
4  "use strict";
5
6  // Define your library strictly...
7})();
8
9// Non-strict code...

Press true if you believe the statement is correct, or false otherwise.

The use strict literal is entered at the top of a JavaScript program or at the top of a function. It helps you write safer JavaScript code by throwing an error if a global variable is created by mistake. For example, the following program will throw an error:

Source
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Let's test your knowledge. Is this statement true or false?

A polyfill is a UI library in Javascript.

Press true if you believe the statement is correct, or false otherwise.

A polyfill is code (or a plugin) that would allow you to have some specific functionality only found in "modern" browsers. It allows that feature to also work in other browsers that do not have the support for that functionality built in.

  • Polyfills are not part of the HTML5 standard
  • Polyfilling is not limited to Javascript
Source

Build your intuition. Is this statement true or false?

null and undefined are identical aliases in JavaScript

Press true if you believe the statement is correct, or false otherwise.

JavaScript (and by extension TypeScript) has two bottom types with no values: null and undefined. They are intended to mean different things:

  • If something hasn't been initialized, it's undefined.
  • If something is currently unavailable, it's null.
Info Screen

Try this exercise. Fill in the missing part by typing it in.

The follow code will output ___.

JAVASCRIPT
1(function() {
2  var a = b = 5;
3})();
4
5console.log(b);

Write the missing line below.

This code will output 5 despite seeming as if the variable was declared within a function and can't be accessed outside of it. This is because

JAVASCRIPT
1var a = b = 5;

is interpreted the following way:

JAVASCRIPT
1var a = b;
2b = 5;

But b is not declared anywhere in the function with var so it is set equal to 5 in the global scope.

Source
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Let's test your knowledge. Click the correct answer from the options.

The following code will output ___.

JAVASCRIPT
1var x = { foo : 1};
2var output = (function() {
3  delete x.foo;
4  return x.foo;
5})();
6
7console.log(output);

Click the option that best answers the question.

  • true
  • false
  • undefined
  • 5

This code will output undefined as output. The delete operator is used to delete a property from an object. Here, x is an object which has foo as a property. From the self-invoking function, we are deleting the foo property of object x. After deletion, we are trying to reference the deleted property foo, which results in undefined.

Source
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Try this exercise. Fill in the missing part by typing it in.

The follow code will output ___.

JAVASCRIPT
1var output = (function(x) {
2  delete x;
3  return x;
4})(1);
5
6console.log(output);

Write the missing line below.

The above code will output 1 as output. The delete operator is used to delete property from object. Here x is not an object it's a global variable of type number.

Source

The specific list of "falsy" values in JavaScript is as follows:

  • "" (empty string)
  • 0, -0, NaN (invalid number)
  • null, undefined
  • false

Any value that's not on this "falsy" list is "truthy." Here are some examples of those:

  • "hello"
  • 42
  • true
  • [ ], [ 1, "2", 3 ] (arrays)
  • { }, { a: 42 } (objects)
  • function foo() { .. } (functions)

Build your intuition. Is this statement true or false?

Hoisting is the concept in which Javascript, by default, moves all declarations to the very bottom of the current scope for easy access.

Press true if you believe the statement is correct, or false otherwise.

Hoistingis the concept in which Javascript, by default, moves all declarations to the top of the current scope. As such, a variable can be used before it has been declared.

Note that Javascript only hoists declarations and not initializations.

Source

There are two types of hoisting:

  • variable hoisting - rare
  • function hoisting - more common
Info Screen

Wherever a var (or function declaration) appears inside a scope, that declaration is taken to belong to the entire scope and accessible everywhere throughout.

JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

Are you sure you're getting this? Fill in the missing part by typing it in.

The output of the following code is ___.

JAVASCRIPT
1var output = (function(x) {
2  delete x;
3  return x;
4})(0);
5
6console.log(output);

Write the missing line below.

This code will output 0 as output. delete operator is used to delete a property from an object. Here x is not an object it's local variable. delete operator doesn't affect local variables.

Source
JAVASCRIPT
OUTPUT
:001 > Cmd/Ctrl-Enter to run, Cmd/Ctrl-/ to comment

One Pager Cheat Sheet

  • JavaScript's type coercion changes argument values to ensure that the correct types are used in expressions, both implicitly and explicitly.
  • In JavaScript, explicit coercion occurs when a value or expression is explicitly converted to a different data type.
  • The typeof operator is used to determine the data type of a given value and return a string that identifies its type.
  • JavaScript provides a typeof operator that can examine a value and tell you its type.
  • Using === allows you to compare two values and determine if they are equal and of the same type.
  • JavaScript has both strict and type-converting comparisons to check for value equality, with strict comparison disallowing coercion and abstract comparison allowing it.
  • The scope in JavaScript determines the visibility and lifetime of variables and functions, and defines how and where these variables can be accessed based on their context of declaration.
  • Variables in JavaScript are associated with a particular scope, which determine their availability to code found lexically within a block and the ability to make their names unique among the same scope.
  • A callback is a flexible and modular programming pattern which increases code abstraction and maintains code maintainability.
  • A callback function is passed to another function as an argument and executed after some operation has been completed.
  • Strict Mode is a feature of ECMAScript 5 (ES5) that helps to prevent certain actions and make code more likely to throw exceptions when errors arise by using the "use strict" statement.
  • The use strict literal helps to prevent errors by throwing an error if a global variable is created unintentionally.
  • No, a polyfill (also known as a shim) is not a UI library in JavaScript; it is code that replicates the expected functionality of modern browsers so that older browsers can also run a particular application or webpage.
  • Polyfills are pieces of code or plugins that enable modern functionality in browsers that have not implemented it natively, and it is not exclusive to Javascript.
  • No value is intentionally absent when null is used, while undefined means the variable is unassigned and has not been declared.
  • JavaScript and TypeScript have two bottom types, null and undefined, which are intended to indicate different states of something either uninitialized or currently unavailable.
  • The code will output 5 because b was declared without the var keyword, making it globally available, whereas a was declared with the var keyword and was only available within the function.
  • The code uses a variablebdeclared in **global scope** which allows it to output5even though it appears to be declared within a function.
  • The property foo of the object x has been deleted, therefore x.foo will return undefined.
  • The delete operator is used to delete the foo property of object x, resulting in undefined when attempting to reference it.
  • The delete operator is used to delete a global variable of type number (in this case, x) from an object.
  • In JavaScript, any value that's not null, undefined, "", 0, -0, NaN or false is considered "truthy".
  • JavaScript's hoisting behavior allows variables and functions to be accessed before they are declared, though the actual values and logic within them remain in their original place.
  • Javascript moves all declarations to the top of the current scope, allowing a variable to be used before it has been declared, but only with variable hoisting (less common) and function hoisting (more common).
  • The program outputs 0 because of the process of function hoisting and the inability of the delete operator to delete primitive values.
  • The delete operator has no effect on local variables, so the output of this code will be 0.