Coder Social home page Coder Social logo

clouddose / javascript-interview-questions Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aershov24/javascript-interview-questions

0.0 1.0 0.0 14 KB

πŸ”΄ JavaScript Interview Questions and Answers for your next Web Developer Interview

Home Page: https://www.fullstack.cafe

javascript-interview-questions's Introduction

JavaScript Interview Questions and Answers from FullStack.Cafe

You could also find all the answers here πŸ‘‰ https://www.fullstack.cafe/JavaScript.

Q1: What is Coercion in JavaScript?

Answer:

In JavaScript conversion between different two build-in types called coercion. Coercion comes in two forms in JavaScript: explicit and implicit.

Here's an example of explicit coercion:

var a = "42";

var b = Number( a );

a;				// "42"
b;				// 42 -- the number!

And here's an example of implicit coercion:

var a = "42";

var b = a * 1;	// "42" implicitly coerced to 42 here

a;				// "42"
b;				// 42 -- the number!

πŸ”— Source: FullStack.Cafe

Q2: What is Scope in JavaScript? ⭐

Answer:

In JavaScript, each function gets its own scope. Scope is basically a collection of variables as well as the rules for how those variables are accessed by name. Only code inside that function can access that function's scoped variables.

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

πŸ”— Source: FullStack.Cafe

Q3: Explain equality in JavaScript ⭐

Answer:

JavaScript has both strict and type–converting comparisons:

  • Strict comparison (e.g., ===) checks for value equality without allowing coercion
  • Abstract comparison (e.g. ==) checks for value equality with coercion allowed
var a = "42";
var b = 42;

a == b;			// true
a === b;		// false

Some simple equalityrules:

  • 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.

πŸ”— Source: FullStack.Cafe

Q4: What is typeof operator? ⭐

Answer:

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

var a;
typeof a;				// "undefined"

a = "hello world";
typeof a;				// "string"

a = 42;
typeof a;				// "number"

a = true;
typeof a;				// "boolean"

a = null;
typeof a;				// "object" -- weird, bug

a = undefined;
typeof a;				// "undefined"

a = { b: "c" };
typeof a;				// "object"

πŸ”— Source: FullStack.Cafe

Q5: What is the object type? ⭐

Answer:

The object type refers to a compound value where you can set properties (named locations) that each hold their own values of any type.

var obj = {
	a: "hello world", // property
	b: 42,
	c: true
};

obj.a;		// "hello world", accessed with doted notation
obj.b;		// 42
obj.c;		// true

obj["a"];	// "hello world", accessed with bracket notation
obj["b"];	// 42
obj["c"];	// true

Bracket notation is also useful if you want to access a property/key but the name is stored in another variable, such as:

var obj = {
	a: "hello world",
	b: 42
};

var b = "a";

obj[b];			// "hello world"
obj["b"];		// 42

πŸ”— Source: FullStack.Cafe

Q6: Explain arrays in JavaScript ⭐

Answer:

An array is an object that holds values (of any type) not particularly in named properties/keys, but rather in numerically indexed positions:

var arr = [
	"hello world",
	42,
	true
];

arr[0];			// "hello world"
arr[1];			// 42
arr[2];			// true
arr.length;		// 3

typeof arr;		// "object"

πŸ”— Source: FullStack.Cafe

Q7: Explain Values and Types in JavaScript ⭐⭐

Answer:

JavaScript has typed values, not typed variables. The following built-in types are available:

  • string
  • number
  • boolean
  • null and undefined
  • object
  • symbol (new to ES6)

πŸ”— Source: FullStack.Cafe

Q8: Explain Null and Undefined in JavaScript ⭐⭐

Answer:

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

  • Something hasn't been initialized : undefined.
  • Something is currently unavailable: null.

πŸ”— Source: FullStack.Cafe

Q9: What is strict mode? ⭐⭐

Answer:

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.

// Non-strict code...

(function(){
  "use strict";

  // Define your library strictly...
})();

// Non-strict code...

πŸ”— Source: FullStack.Cafe

Q10: What is a Polyfill? ⭐⭐

Answer:

A polyfill is essentially the specific code (or plugin) that would allow you to have some specific functionality that you expect in current or β€œmodern” browsers 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: programmerinterview.com

Q11: What is let keyword in JavaScript? ⭐⭐

Answer:

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

πŸ”— Source: github.com/getify

Q12: Being told that an unsorted array contains (n - 1) of n consecutive numbers (where the bounds are defined), find the missing number in O(n) time ⭐⭐

Answer:

// The output of the function should be 8
var arrayOfIntegers = [2, 5, 1, 4, 9, 6, 3, 7];
var upperBound = 9;
var lowerBound = 1;

findMissingNumber(arrayOfIntegers, upperBound, lowerBound); // 8

function findMissingNumber(arrayOfIntegers, upperBound, lowerBound) {
  // Iterate through array to find the sum of the numbers
  var sumOfIntegers = 0;
  for (var i = 0; i < arrayOfIntegers.length; i++) {
    sumOfIntegers += arrayOfIntegers[i];
  }

  // Find theoretical sum of the consecutive numbers using a variation of Gauss Sum.
  // Formula: [(N * (N + 1)) / 2] - [(M * (M - 1)) / 2];
  // N is the upper bound and M is the lower bound

  upperLimitSum = (upperBound * (upperBound + 1)) / 2;
  lowerLimitSum = (lowerBound * (lowerBound - 1)) / 2;

  theoreticalSum = upperLimitSum - lowerLimitSum;

  return theoreticalSum - sumOfIntegers;
}

πŸ”— Source: https://github.com/kennymkchan

Q13: Remove duplicates of an array and return an array of only unique elements ⭐⭐

Answer:

// ES6 Implementation
var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8];

Array.from(new Set(array)); // [1, 2, 3, 5, 9, 8]

// ES5 Implementation
var array = [1, 2, 3, 5, 1, 5, 9, 1, 2, 8];

uniqueArray(array); // [1, 2, 3, 5, 9, 8]

function uniqueArray(array) {
  var hashmap = {};
  var unique = [];

  for(var i = 0; i < array.length; i++) {
    // If key returns undefined (unique), it is evaluated as false.
    if(!hashmap.hasOwnProperty(array[i])) {
      hashmap[array[i]] = 1;
      unique.push(array[i]);
    }
  }

  return unique;
}

πŸ”— Source: https://github.com/kennymkchan

Q14: Given a string, reverse each word in the sentence ⭐⭐

Questions Details:

For example Welcome to this Javascript Guide! should be become emocleW ot siht tpircsavaJ !ediuG

Answer:

var string = "Welcome to this Javascript Guide!";

// Output becomes !ediuG tpircsavaJ siht ot emocleW
var reverseEntireSentence = reverseBySeparator(string, "");

// Output becomes emocleW ot siht tpircsavaJ !ediuG
var reverseEachWord = reverseBySeparator(reverseEntireSentence, " ");

function reverseBySeparator(string, separator) {
  return string.split(separator).reverse().join(separator);
}

πŸ”— Source: https://github.com/kennymkchan

Q15: Implement enqueue and dequeue using only two stacks ⭐⭐

Answer:

Enqueue means to add an element, dequeue to remove an element.

var inputStack = []; // First stack
var outputStack = []; // Second stack

// For enqueue, just push the item into the first stack
function enqueue(stackInput, item) {
  return stackInput.push(item);
}

function dequeue(stackInput, stackOutput) {
  // Reverse the stack such that the first element of the output stack is the
  // last element of the input stack. After that, pop the top of the output to
  // get the first element that was ever pushed into the input stack
  if (stackOutput.length <= 0) {
    while(stackInput.length > 0) {
      var elementToOutput = stackInput.pop();
      stackOutput.push(elementToOutput);
    }
  }

  return stackOutput.pop();
}

πŸ”— Source: https://github.com/kennymkchan

Q16: Explain event bubbling and how one may prevent it ⭐⭐

Answer:

Event bubbling is the concept in which an event triggers at the deepest possible element, and triggers on parent elements in nesting order. As a result, when clicking on a child element one may exhibit the handler of the parent activating.

One way to prevent event bubbling is using event.stopPropagation() or event.cancelBubble on IE < 9.

πŸ”— Source: https://github.com/kennymkchan

Q17: Write a "mul" function which will properly when invoked as below syntax. ⭐⭐

Questions Details:

console.log(mul(2)(3)(4)); // output : 24
console.log(mul(4)(3)(4)); // output : 48

Answer:

function mul (x) {
  return function (y) { // anonymous function
    return function (z) { // anonymous function
      return x * y * z;
    };
  };
}

Here mul function accept the first argument and return anonymous function which take the second parameter and return anonymous function which take the third parameter and return multiplication of arguments which is being passed in successive

In JavaScript function defined inside has access to outer function variable and function is the first class object so it can be returned by function as well and passed as argument in another function.

  • A function is an instance of the Object type
  • A function can have properties and has a link back to its constructor method
  • Function can be stored as variable
  • Function can be pass as a parameter to another function
  • Function can be returned from function

πŸ”— Source: github.com/ganqqwerty

Q18: How to empty an array in JavaScript? ⭐⭐

Questions Details:

var arrayList =  ['a', 'b', 'c', 'd', 'e', 'f'];

How could we empty the array above?

Answer:

Method 1

arrayList = [];

Above code will set the variable arrayList to a new empty array. This is recommended if you don't have references to the original array arrayList anywhere else because It will actually create a new empty array. You should be careful with this way of empty the array, because if you have referenced this array from another variable, then the original reference array will remain unchanged, Only use this way if you have only referenced the array by its original variable arrayList.

For Instance:

var arrayList = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var anotherArrayList = arrayList;  // Referenced arrayList by another variable
arrayList = []; // Empty the array
console.log(anotherArrayList); // Output ['a', 'b', 'c', 'd', 'e', 'f']

Method 2

arrayList.length = 0;

Above code will clear the existing array by setting its length to 0. This way of empty the array also update all the reference variable which pointing to the original array. This way of empty the array is useful when you want to update all the another reference variable which pointing to arrayList.

For Instance:

var arrayList = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var anotherArrayList = arrayList;  // Referenced arrayList by another variable
arrayList.length = 0; // Empty the array by setting length to 0
console.log(anotherArrayList); // Output []

Method 3

arrayList.splice(0, arrayList.length);

Above implementation will also work perfectly. This way of empty the array will also update all the references of the original array.

var arrayList = ['a', 'b', 'c', 'd', 'e', 'f']; // Created array
var anotherArrayList = arrayList;  // Referenced arrayList by another variable
arrayList.splice(0, arrayList.length); // Empty the array by setting length to 0
console.log(anotherArrayList); // Output []

Method 4

while(arrayList.length) {
  arrayList.pop();
}

Above implementation can also empty the array. But not recommended to use often.

πŸ”— Source: github.com/ganqqwerty

Q19: How to check if an object is an array or not? Provide some code. ⭐⭐

Answer:

The best way to find whether an object is instance of a particular class or not using toString method from Object.prototype

var arrayList = [1 , 2, 3];

One of the best use cases of type checking of an object is when we do method overloading in JavaScript. For understanding this let say we have a method called greet which take one single string and also a list of string, so making our greet method workable in both situation we need to know what kind of parameter is being passed, is it single value or list of value?

function greet(param) {
  if() {
    // here have to check whether param is array or not
  }
  else {
  }
}

However, in above implementation it might not necessary to check type for array, we can check for single value string and put array logic code in else block, let see below code for the same.

 function greet(param) {
   if(typeof param === 'string') {
   }
   else {
     // If param is of type array then this block of code would execute
   }
 }

Now it's fine we can go with above two implementations, but when we have a situation like a parameter can be single value, array, and object type then we will be in trouble.

Coming back to checking type of object, As we mentioned that we can use Object.prototype.toString

if(Object.prototype.toString.call(arrayList) === '[object Array]') {
  console.log('Array!');
}

If you are using jQuery then you can also used jQuery isArray method:

if($.isArray(arrayList)) {
  console.log('Array');
} else {
  console.log('Not an array');
}

FYI jQuery uses Object.prototype.toString.call internally to check whether an object is an array or not.

In modern browser, you can also use:

Array.isArray(arrayList);

Array.isArray is supported by Chrome 5, Firefox 4.0, IE 9, Opera 10.5 and Safari 5

πŸ”— Source: github.com/ganqqwerty

Q20: How would you use a closure to create a private counter? ⭐⭐

Answer:

You can create a function within an outer function (a closure) that allows you to update a private variable but the variable wouldn't be accessible from outside the function without the use of a helper function.

function counter() {
  var _counter = 0;
  // return an object with several functions that allow you
  // to modify the private _counter variable
  return {
    add: function(increment) { _counter += increment; },
    retrieve: function() { return 'The counter is currently at: ' + _counter; }
  }
}

// error if we try to access the private variable like below
// _counter;

// usage of our counter function
var c = counter();
c.add(5); 
c.add(9); 

// now we can access the private variable in the following way
c.retrieve(); // => The counter is currently at: 14

πŸ”— Source: coderbyte.com

Q21: Write a function that would allow you to do this. ⭐⭐

Questions Details:

var addSix = createBase(6);
addSix(10); // returns 16
addSix(21); // returns 27

Answer:

You can create a closure to keep the value passed to the function createBase even after the inner function is returned. The inner function that is being returned is created within an outer function, making it a closure, and it has access to the variables within the outer function, in this case the variable baseNumber.

function createBase(baseNumber) {
  return function(N) {
    // we are referencing baseNumber here even though it was declared
    // outside of this function. Closures allow us to do this in JavaScript
    return baseNumber + N;
  }
}

var addSix = createBase(6);
addSix(10);
addSix(21);

πŸ”— Source: coderbyte.com

Q22: How would you check if a number is an integer? ⭐⭐

Answer:

A very simply way to check if a number is a decimal or integer is to see if there is a remainder left when you divide by 1.

function isInt(num) {
  return num % 1 === 0;
}

console.log(isInt(4)); // true
console.log(isInt(12.2)); // false
console.log(isInt(0.3)); // false

πŸ”— Source: coderbyte.com

Q23: What does "use strict" do? ⭐⭐

Answer:

The use strict literal is entered at the top of a JavaScript program or at the top of a function and 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:

function doSomething(val) {
  "use strict"; 
  x = val + 10;
}`

It will throw an error because x was not defined and it is being set to some value in the global scope, which isn't allowed with use strict The small change below fixes the error being thrown:

function doSomething(val) {
  "use strict"; 
  var x = val + 10;
}

πŸ”— Source: coderbyte.com

Q24: Explain what a callback function is and provide a simple example. ⭐⭐

Answer:

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

function modifyArray(arr, callback) {
  // do something to arr here
  arr.push(100);
  // then execute the callback function that was passed
  callback();
}

var arr = [1, 2, 3, 4, 5];

modifyArray(arr, function() {
  console.log("array has been modified", arr);
});

πŸ”— Source: coderbyte.com

Q25: What language constructions do you use for iterating over object properties and array items? ⭐⭐

Answer:

For objects:

  • for loops - for (var property in obj) { console.log(property); }. However, this will also iterate through its inherited properties, and you will add an obj.hasOwnProperty(property) check before using it.
  • Object.keys() - Object.keys(obj).forEach(function (property) { ... }). Object.keys() is a static method that will lists all enumerable properties of the object that you pass it.
  • Object.getOwnPropertyNames() - Object.getOwnPropertyNames(obj).forEach(function (property) { ... }). Object.getOwnPropertyNames() is a static method that will lists all enumerable and non-enumerable properties of the object that you pass it.

For arrays:

  • for loops - for (var i = 0; i < arr.length; i++). The common pitfall here is that var is in the function scope and not the block scope and most of the time you would want block scoped iterator variable. ES2015 introduces let which has block scope and it is recommended to use that instead. So this becomes: for (let i = 0; i < arr.length; i++).
  • forEach - arr.forEach(function (el, index) { ... }). This construct can be more convenient at times because you do not have to use the index if all you need is the array elements. There are also the every and some methods which will allow you to terminate the iteration early.

Most of the time, I would prefer the .forEach method, but it really depends on what you are trying to do. for loops allow more flexibility, such as prematurely terminate the loop using break or incrementing the iterator more than once per loop.

πŸ”— Source: github.com/yangshun

Q26: What are some of the advantages/disadvantages of writing JavaScript code in a language that compiles to JavaScript? ⭐⭐

Answer:

Some examples of languages that compile to JavaScript include CoffeeScript, Elm, ClojureScript, PureScript, and TypeScript.

Advantages:

  • Fixes some of the longstanding problems in JavaScript and discourages JavaScript anti-patterns.
  • Enables you to write shorter code, by providing some syntactic sugar on top of JavaScript, which I think ES5 lacks, but ES2015 is awesome.
  • Static types are awesome (in the case of TypeScript) for large projects that need to be maintained over time.

Disadvantages:

  • Require a build/compile process as browsers only run JavaScript and your code will need to be compiled into JavaScript before being served to browsers.
  • Debugging can be a pain if your source maps do not map nicely to your pre-compiled source.
  • Most developers are not familiar with these languages and will need to learn it. There's a ramp up cost involved for your team if you use it for your projects.
  • Smaller community (depends on the language), which means resources, tutorials, libraries, and tooling would be harder to find.
  • IDE/editor support might be lacking.
  • These languages will always be behind the latest JavaScript standard.
  • Developers should be cognizant of what their code is being compiled toβ€Šβ€”β€Šbecause that is what would actually be running, and that is what matters in the end.

Practically, ES2015 has vastly improved JavaScript and made it much nicer to write. I don't really see the need for CoffeeScript these days.

πŸ”— Source: github.com/yangshun

Q27: Why is it, in general, a good idea to leave the global scope of a website as-is and never touch it? ⭐⭐

Answer:

Every script has access to the global scope, and if everyone uses the global namespace to define their variables, collisions will likely occur. Use the module pattern (IIFEs) to encapsulate your variables within a local namespace.

πŸ”— Source: github.com/yangshun

Q28: Why would you use something like the load event? Does this event have disadvantages? Do you know any alternatives, and why would you use those? ⭐⭐

Answer:

The load event fires at the end of the document loading process. At this point, all of the objects in the document are in the DOM, and all the images, scripts, links and sub-frames have finished loading.

The DOM event DOMContentLoaded will fire after the DOM for the page has been constructed, but do not wait for other resources to finish loading. This is preferred in certain cases when you do not need the full page to be loaded before initializing.

πŸ”— Source: github.com/yangshun

Q29: FizzBuzz Challenge ⭐⭐

Questions Details:

Create a for loop that iterates up to 100 while outputting "fizz" at multiples of 3, "buzz" at multiples of 5 and "fizzbuzz" at multiples of 3 and 5.

Answer:

Check out this version of FizzBuzz:

for (let i = 1; i <= 100; i++) {
  let f = i % 3 == 0,
    b = i % 5 == 0;
  console.log(f ? (b ? 'FizzBuzz' : 'Fizz') : b ? 'Buzz' : i);
}

πŸ”— Source: github.com/yangshun

Q30: Make this work ⭐⭐

Questions Details:

duplicate([1, 2, 3, 4, 5]); // [1,2,3,4,5,1,2,3,4,5]

Answer:

function duplicate(arr) {
  return arr.concat(arr);
}

duplicate([1, 2, 3, 4, 5]); // [1,2,3,4,5,1,2,3,4,5]

πŸ”— Source: github.com/yangshun

Q31: Explain the same-origin policy with regards to JavaScript. ⭐⭐

Answer:

The same-origin policy prevents JavaScript from making requests across domain boundaries. An origin is defined as a combination of URI scheme, hostname, and port number. This policy prevents a malicious script on one page from obtaining access to sensitive data on another web page through that page's Document Object Model.

πŸ”— Source: github.com/yangshun

Q32: What is the difference between == and ===? ⭐⭐

Answer:

== is the abstract equality operator while === is the strict equality operator. The == operator will compare for equality after doing any necessary type conversions. The === operator will not do type conversion, so if two values are not the same type === will simply return false. When using ==, funky things can happen, such as:

1 == '1'; // true
1 == [1]; // true
1 == true; // true
0 == ''; // true
0 == '0'; // true
0 == false; // true

My advice is never to use the == operator, except for convenience when comparing against null or undefined, where a == null will return true if a is null or undefined.

var a = null;
console.log(a == null); // true
console.log(a == undefined); // true

πŸ”— Source: github.com/yangshun

Q33: What's the difference between host objects and native objects? ⭐⭐

Answer:

  • Native objects are objects that are part of the JavaScript language defined by the ECMAScript specification, such as String, Math, RegExp, Object, Function, etc.
  • Host objects are provided by the runtime environment (browser or Node), such as window, XMLHTTPRequest, etc.

πŸ”— Source: github.com/yangshun

Q34: Is there anyway to force using strict mode in Node.js? ⭐⭐

Answer:

you can place

"use strict";

at the top of your file in node >= 0.10.7, but if you want your whole app to run in strict (including external modules) you can do this

node --use_strict

πŸ”— Source: stackoverflow.com

Q35: What's the difference between throw Error('msg') vs throw new Error('msg')? ⭐⭐

Questions Details:

var err1 = Error('message');
var err2 = new Error('message');

Which one is correct and why?

Answer:

Both are fine; the function call Error(…) is equivalent to the object creation expression new Error(…) with the same arguments.

πŸ”— Source: stackoverflow.com

Q36: Provide some examples of non-bulean value coercion to a boolean one ⭐⭐⭐

See πŸ‘‰ Answer

Q37: How to compare two objects in JavaScript? ⭐⭐⭐

See πŸ‘‰ Answer

Q38: What is the difference between anonymous and named functions? ⭐⭐⭐

See πŸ‘‰ Answer

Q39: Describe closure concept in JavaScript as best as you could ⭐⭐⭐

See πŸ‘‰ Answer

Q40: What is the difference between a shim and a polyfill? ⭐⭐⭐

See πŸ‘‰ Answer

Q41: Could you explain the difference between ES5 and ES6 ⭐⭐⭐

See πŸ‘‰ Answer

Q42: Given an array of integers, find the largest product yielded from three of the integers ⭐⭐⭐

See πŸ‘‰ Answer

Q43: Given an array of integers, find the largest difference between two elements such that the element of lesser value must come before the greater element ⭐⭐⭐

See πŸ‘‰ Answer

Q44: Find the intersection of two arrays. An intersection would be the common elements that exists within both arrays. In this case, these elements should be unique! ⭐⭐⭐

See πŸ‘‰ Answer

Q45: Given two strings, return true if they are anagrams of one another ⭐⭐⭐

Questions Details:

For example: Mary is an anagram of Army

See πŸ‘‰ Answer

Q46: Write a recursive function that returns the binary string of a given decimal number ⭐⭐⭐

See πŸ‘‰ Answer

Q47: Explain the difference between "undefined" and "not defined" in JavaScript ⭐⭐⭐

See πŸ‘‰ Answer

Q48: What will be the output of the following code? ⭐⭐⭐

Questions Details:

var y = 1;
if (function f() {}) {
  y += typeof f;
}
console.log(y);

See πŸ‘‰ Answer

Q49: What is the drawback of creating true private in JavaScript? ⭐⭐⭐

See πŸ‘‰ Answer

Q50: What will be the output of the following code? ⭐⭐⭐

Questions Details:

var x = 1;
var output = (function() {
  delete x;
  return x;
})();

console.log(output);

See πŸ‘‰ Answer

Q51: What will be the output of the following code? ⭐⭐⭐

Questions Details:

var x = { foo : 1};
var output = (function() {
  delete x.foo;
  return x.foo;
})();

console.log(output);

See πŸ‘‰ Answer

Q52: What is IIFEs (Immediately Invoked Function Expressions)? ⭐⭐⭐

See πŸ‘‰ Answer

Q53: What will the following code output? ⭐⭐⭐

Questions Details:

(function() {
  var a = b = 5;
})();

console.log(b);

See πŸ‘‰ Answer

Q54: Write a function that would allow you to do this ⭐⭐⭐

Questions Details:

multiply(5)(6);

See πŸ‘‰ Answer

Q55: Check if a given string is a palindrome. Case sensitivity should be taken into account. ⭐⭐⭐

See πŸ‘‰ Answer

Q56: What's the difference between using β€œlet” and β€œvar” to declare a variable in ES6? ⭐⭐⭐

See πŸ‘‰ Answer

Q57: When should I use Arrow functions in ES6? ⭐⭐⭐

See πŸ‘‰ Answer

Q58: What is the motivation for bringing Symbols to ES6? ⭐⭐⭐

See πŸ‘‰ Answer

Q59: What are the benefits of using spread syntax in ES6 and how is it different from rest syntax? ⭐⭐⭐

See πŸ‘‰ Answer

Q60: What is 'Currying'? ⭐⭐⭐

See πŸ‘‰ Answer

Q61: What is the definition of a higher-order function? ⭐⭐⭐

See πŸ‘‰ Answer

Q62: What are the differences between ES6 class and ES5 function constructors? ⭐⭐⭐

See πŸ‘‰ Answer

Q63: Explain the differences on the usage of foo between function foo() {} and var foo = function() {} ⭐⭐⭐

See πŸ‘‰ Answer

Q64: What are the advantages and disadvantages of using "use strict"? ⭐⭐⭐

See πŸ‘‰ Answer

Q65: What is the difference between document load event and document DOMContentLoaded event? ⭐⭐⭐

Questions Details:

The DOMContentLoaded event is fired when the initial HTML document has been completely loaded and parsed, without waiting for stylesheets, images, and subframes to finish loading.

window's load event is only fired after the DOM and all dependent resources and assets have loaded.

See πŸ‘‰ Answer

Q66: Why is extending built-in JavaScript objects not a good idea? ⭐⭐⭐

See πŸ‘‰ Answer

Q67: Explain Function.prototype.bind. ⭐⭐⭐

See πŸ‘‰ Answer

Q68: What's the difference between .call and .apply? ⭐⭐⭐

See πŸ‘‰ Answer

Q69: What's a typical use case for anonymous functions? ⭐⭐⭐

See πŸ‘‰ Answer

Q70: What is a closure, and how/why would you use one? ⭐⭐⭐

See πŸ‘‰ Answer

Q71: What do you think of AMD vs CommonJS? ⭐⭐⭐

See πŸ‘‰ Answer

Q72: Suggest one simple way of removing duplicates from an array using ES6 ⭐⭐⭐

See πŸ‘‰ Answer

Q73: Why should we use ES6 classes? ⭐⭐⭐

See πŸ‘‰ Answer

Q74: What is the preferred syntax for defining enums in JavaScript? ⭐⭐⭐

See πŸ‘‰ Answer

Q75: Explain the difference between Object.freeze() vs const ⭐⭐⭐

See πŸ‘‰ Answer

Q76: What is generator in JS? ⭐⭐⭐

See πŸ‘‰ Answer

Q77: When should we use generators in ES6? ⭐⭐⭐

See πŸ‘‰ Answer

Q78: What is Hoisting in JavaScript? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q79: How does the β€œthis” keyword work? Provide some code examples. ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q80: What is the "new" keyword in JavaScript? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q81: What does the term "Transpiling" stand for? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q82: Explain prototype inheritance in JavaScript? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q83: Check if a given string is a isomorphic ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q84: Create a function that will evaluate if a given expression has balanced parentheses using stacks ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q85: Write a recursive function that performs a binary search ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q86: Given an integer, determine if it is a power of 2. If so, return that number, else return -1 ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q87: Explain what is hoisting in Javascript ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q88: What is β€œclosure” in javascript? Provide an example? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q89: What will be the output of the following code? ⭐⭐⭐⭐

Questions Details:

var output = (function(x) {
  delete x;
  return x;
})(0);

console.log(output);

See πŸ‘‰ Answer

Q90: What will be the output of the following code? ⭐⭐⭐⭐

Questions Details:

var Employee = {
  company: 'xyz'
}
var emp1 = Object.create(Employee);
delete emp1.company
console.log(emp1.company);

See πŸ‘‰ Answer

Q91: Describe the JS module design pattern ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q92: Explain the Prototype Design Pattern ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q93: When would you use the "bind" function? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q94: How would you add your own method to the Array object so the following code would work? ⭐⭐⭐⭐

Questions Details:

var arr = [1, 2, 3, 4, 5];
var avg = arr.average();
console.log(avg);

See πŸ‘‰ Answer

Q95: What will the following code output? ⭐⭐⭐⭐

Questions Details:

0.1 + 0.2 === 0.3

See πŸ‘‰ Answer

Q96: How would you create a private variable in JavaScript? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q97: What is the Temporal Dead Zone in ES6? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q98: When should you NOT use arrow functions in ES6? Name three or more cases. ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q99: What are the actual uses of ES6 WeakMap? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q100: How can you share code between files? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q101: Can you give an example for destructuring an object or an array in ES6? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q102: Explain how JSONP works (and how it's not really Ajax) ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q103: Explain difference between: function Person(){}, var person = Person(), and var person = new Person()? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q104: Can you describe the main difference between a .forEach loop and a .map() loop and why you would pick one versus the other? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q105: What's the difference between a variable that is: null, undefined or undeclared? How would you go about checking for any of these states? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q106: Explain why the following doesn't work as an IIFE. What needs to be changed to properly make it an IIFE? ⭐⭐⭐⭐

Questions Details:

function foo(){ }();

See πŸ‘‰ Answer

Q107: Could you compare usage of Module Pattern vs Constructor/Prototype pattern? ⭐⭐⭐⭐

See πŸ‘‰ Answer

Q108: Describe the Revealing Module Pattern design pattern ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q109: What's the difference between ES6 Map and WeakMap? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q110: Can you give an example of a curry function and why this syntax offers an advantage? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q111: Is JavaScript a pass-by-reference or pass-by-value language? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q112: How to "deep-freeze" object in JavaScript? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q113: In JavaScript, why is the β€œthis” operator inconsistent? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q114: What is the difference between the await keyword and the yield keyword? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q115: Is it possible to reset an ECMAScript 6 generator to its initial state? ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Q116: Compare Async/Await and Generators usage to achive same functionality ⭐⭐⭐⭐⭐

See πŸ‘‰ Answer

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.