10 JavaScript common interview questions.

2. Null Vs Undefined

let demo;
console.log(demo); //shows undefined
alert(typeof demo); //shows undefined
let demo = null;
console.log(demo); //shows null
alert(typeof demo); //shows object

3. == Vs === (Double equals Vs Triple equals sign)

11 == '11' // returns true 
but,
11 === '11' // returns false

4. Implicit coercion

2 + '2' // returns 4
2 * [2] // returns 4

5. Apply map, filter, find on an array of objects

6. Scope

7. Block Scope

8. Find the largest element of an array

const myArr = [2, 3, 7, 6, 4, 9];
console.log(Math.max.apply(null, myArr)); // returns 9

9. Sum of all numbers in an array

const arr = [1, 2, 3, 4, 5];  
// Getting sum of numbers
const reducer = (accumulator, currentValue) => accumulator + currentValue;
console.log(array1.reduce(reducer)); // returns 15

10. Remove duplicate item from an array

function findUnique(array){
let uniqueArray = [];

// Loop through array values
for(i=0; i < array.length; i++){
if(uniqueArray.indexOf(array[i]) === -1) {
uniqueArray.push(array[i]);
}
}
return uniqueArray;
}

const names = ["John", "Peter", "Clark", "Harry", "John", "Alice"];
let uniqueNames = getUnique(names);
console.log(uniqueNames); // Prints: ["John", "Peter", "Clark", "Harry", "Alice"]

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store