55 #javascript interview questions
Tags: javascript, code, webdev, career
Published: 2020-02-17 14:07:11


###1. 
```
 const myString = 'Hello 2020'; 
 myString = 'Hello World!';
 console.log(myString)//"Hello World!"

```
   
 what block scope keyword when changed produces the  above console.log output?


###2
```
 let students = 0;
 let classroom = false;
 if(students > 10) {
    let classroom = true;
   }
console.log(classroom);

```
What is console-.log'd? (false or true)

###3

```
let num1 = [1,2,3,4];
let num2 = [10,20,30,1];
let num3 = [100,200,300,1]; 

```
Find the common elements in all 3 arrays 

###4

```
function checkout(price,___){
  if(price > 100){
   ___( ____ );
  }
}

function _____( ____){
  let discount = ____ - (.10 *_____);
   console.log("the total is" + discount)
}
checkout(110,cb);
```

###5

```
const yummies = ['Ice-cream','Cupcake','Donut','Cupcake'];

```
Using filter( ), return the unique elements from "yummies"


###6
Code a function that returns a promise


###7 

```
const composers = [{
 Name: 'Beethoven',
 Genre: 'Classical',
 Rating: '9'
},
{
 Name: 'Mozart',
 Genre: 'Classical',
 Rating: '10'
 }]
```
Use map () to create a new array of objects with the rating & last name

###8

```
let c = 0;
let d = false;
console.log(c !== d);
```

###9

```
let catPowers ={ 
 snarky: true,
 napzinger: "Zzzzz",
 gobbler: function(){
  if(this.snarky === true)
    return this.snarky;
  }
}
```
return only the values of the catPowers object without using for-in

###10

```
let numArray1 =[1,2,3];
let numArray2= numArray1;
numArray2.push(4);

```
Take a guess what will console.log(numArray1) be?

###11
What #ES6 method will you use to create a shallow-copied array of characters from this string referenced by let myString?

```
let myString = ? ("supercalifragilisticexpialidocious");
```

###12

```
let obj1 = { a: 10, b:20, c:30 }; 
let obj2 = { d: 40, e:50, f:60}; 
let obj3 = { g: 70, h:80, i:90 }; 
let obj;
```
Assign all properties from obj1,obj2, obj3 to obj

###13

```
let devFood = [ "Foo Bar", "Barzinga","Loodles"];
console.log(devFood)//["Foo Bar", "Foo Bar", "Barzinga"];

```
Use an #ES6 method to copy array elements to match the console.log

###14

```
var helloWorld = function(msg){
  alert(msg);
}
helloWorld('Hello World');
```

Re-write this using functional #javascript  

###15

```
let games = ["King's Quest", "Super Mario", "Zelda", "Contra"];
games.splice(2, 0, "Doom", "World of Warcraft");
games.slice(0,2);
console.log(games); // ? What will this be
```

###16

what is the difference between the pass by value and pass by reference with examples 

###17

“innerHTML” can increase the possibility  of a XSS attack. What is an alternative for setting text?

###18

What is the difference between a 🍬ReferenceError and undefined error 🍡

###19

```
for (var i = 0; i < 10; i++) {
setTimeout(function(){
 console.log(i); //what is logged here?
  }, i * 1000 );
}
```

###20

```
 let num = 10;  

 function sum( ) {  
  let  num = 100;  
  document.getElementById('myP').innerHTML =(num+num);  // 20 or 200?
   }   
  
sum( ); 
```

###21

```
console.log(false != '0')
console.log(false !== '0')
```

###22

```
let x = null;
/*Knowing that typeof(x) will return “object”. How do you check for a null value?*/
```
###23

```
let langs = ["JavaScript","C#","Rust","C++","Python"];
  delete langs[3];
  console.log(langs.length);//⭐️
  console.log(langs[3]); //⭐️
```

###24

```
let arre= ["","A",9,"C++",false];
//Empty the above array  
```
###25

```
let myQueue = [];
myQueue.push('a');
myQueue.push('b');
myQueue.push('c');
//Remove the first element in myQueue. 💎HINT: FIFO principle
```

###26

```
console.log(null == undefined) // T or F?
console.log(null === undefined)// T or F?
console.log(typeof(null) === 'object')// T or F?
```

###27

Using in-built methods, implement a stack in #JavaScript and remove the last 2 elements

###28

What is event bubbling?🗨️
Is "false" false?🐻
Is " " false?🐻
How do you increase page load times?💻

###29

```
let person1 = {
  name: "Rocko"
};
let person2 = {
  name: "Rover"
};
Object.freeze(person1);http://person1.name  = "Lara"; 
person2 = person1;
console.log(person1);
console.log(person2);
```

###30

```
let fooBar = new Array(5);
fooBar[2] = "Hello";
console.log(fooBar); //
```
###31

```
let myArr = [1,10,100,1000,10000]
Array.prototype.first = function() {
return this[0];
}
myArr.pop();
console.log(myArr.first()); // ?💫
console.log(myArr); //? 💫

```
###32

What is a closure? Give an example

###33

```
let x =  y = 7;
y= 10;
console.log(x);
console.log(y); 
```

###34

```
let game1 = "The Legend of JavaScript"; 
var game2 = "JortNite";
const game3 = "Super Jario";
console.log(window.game1);💎
console.log(window.game2);💎
console.log(window.game3);💎
```

###35

```
function* generator(num) {
  yield num;
  yield num * 10;
}
let result = generator(100);
console.log(💫);// 100
console.log(💫); //1000
```

###36

```
function factorial(num) { 
  if (num === 0) {
    return 1;
 } else {
   return num* 🌟(num - 1); //replace the star..
   }        
}
console.log(factorial(4));
```

###37

Write a function to console.log the sum of all the elements in an array using recursion

###38

```
console.log(105 < 232 < 350);
console.log(450 > 333 > 120);  
```

###39

```
//replicate without 'class':
class coder{  
 constructor(name){  
  http://this.name =name;  
  }  
 detail(){  
   return(http://this.name );
   }  
  }

```

###40

```
function🐻(i) { 
   let 🔢= function() {
     i++;
    };
    return 🔢; 
}
let 🍎 =  🐻(1000);
let 🍏 = 🐻(1)
🍎(); //?
🍏(); //?

```

###41

```
let 🍇 = new Set();
🍇.add(1);
🍇.add(5);
🍇.add(1,5)
🍇.add(1, 1000)
console.log(🍇.size); // ⭐️
```

###42

```
let 🌠 = [
   [35, 28, 29, 31],
   [33, 24, 25, 29]
];
console.log(🌠[0][2]);

```
A. 35,28 
B. 33, 25
C. 29

###43

```
const  🐸= (user, newUser) => {
  return new Promise ((resolve, reject) => {
    if(user === newUser) {
      resolve();
    } else {
      reject();
    }
    })
}

```

###44

```
/*Re-write this fxn without using an immediately invoked function (with the same functionality):*/

 (function IIFE(){
    console.log( 'hello world!' );
})();

```

###45

```
const animals  = [“🦊”, “🐸”, “🐹”, “🐰”];
animals.length = 10;
console.log(animals[0]); 
animals.length = 2;
console.log(animals[3]); 
```

###46

```
//(hint:https://0.30000000000000004.com/ ) :
⭐️console.log(0.1 + 0.2);
```

###47

Write a fxn to reverse a string

###48

```
const codeShop = {
  company: "Code Factory",
  address: "Square building, 10000 Moon St"
}
let 🐧= Object.create(codeShop);
delete🐧.codeShop;
console.log(🐧.company);//⭐️

//❤️hint: hasOwnProperty
```

###49

```
//⭐️ Duplicate the elements of an array⭐️

function duplicateArr(myArr) {
  return(❓);
}

duplicateArr(["a", "b", "c"]); //["a", "b", "c", "a", "b", "c"]

```

###50

```
//Complete the following fxn:

function funFxn() {
  let secret = "this is a secret";
❓❓❓❓❓
}

let getSecret = funFxn(); // "this is a secret"

```

###51

```
//🍎Convert this to an anonymous fxn in #javascript 

function love(param){
  console.log(`I love ${param}`);
}
love("dogs");

```
###52

Define:

1. Event Loop
2. Callback fxn
3. Stack
4. Task queue
5. Higher Order Fxn
6. Var, Const, Let
7. Lexical Scope
8. Closure
9. Anonymous Fxn
10. Event bubbling

###53

```
let arr = [🍓, 🍓, 🍓, 🍓];
arr.❓❓(🥝, 1, 3); 
console.log(arr)//[🍓, 🥝, 🥝,🍓];
```

###54

White space is retained in ES6 template literals? T/F


###55

```
<h2 id="para1"></h2>

localStorage.❓("guestName", "missLorem");
document.getElementById("para1").innerHTML = localStorage.❓("guestName");
```