DEV Community

Kauress
Kauress

Posted on

55 #javascript interview questions

1.

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

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

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]; 

Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

5

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

Enter fullscreen mode Exit fullscreen mode

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'
 }]
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

9

let catPowers ={ 
 snarky: true,
 napzinger: "Zzzzz",
 gobbler: function(){
  if(this.snarky === true)
    return this.snarky;
  }
}
Enter fullscreen mode Exit fullscreen mode

return only the values of the catPowers object without using for-in

10

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

Enter fullscreen mode Exit fullscreen mode

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");
Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

Assign all properties from obj1,obj2, obj3 to obj

13

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

Enter fullscreen mode Exit fullscreen mode

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

14

var helloWorld = function(msg){
  alert(msg);
}
helloWorld('Hello World');
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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 );
}
Enter fullscreen mode Exit fullscreen mode

20

 let num = 10;  

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

sum( ); 
Enter fullscreen mode Exit fullscreen mode

21

console.log(false != '0')
console.log(false !== '0')
Enter fullscreen mode Exit fullscreen mode

22

let x = null;
/*Knowing that typeof(x) will return β€œobject”. How do you check for a null value?*/
Enter fullscreen mode Exit fullscreen mode

23

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

24

let arre= ["","A",9,"C++",false];
//Empty the above array  
Enter fullscreen mode Exit fullscreen mode

25

let myQueue = [];
myQueue.push('a');
myQueue.push('b');
myQueue.push('c');
//Remove the first element in myQueue. πŸ’ŽHINT: FIFO principle
Enter fullscreen mode Exit fullscreen mode

26

console.log(null == undefined) // T or F?
console.log(null === undefined)// T or F?
console.log(typeof(null) === 'object')// T or F?
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

30

let fooBar = new Array(5);
fooBar[2] = "Hello";
console.log(fooBar); //
Enter fullscreen mode Exit fullscreen mode

31

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

Enter fullscreen mode Exit fullscreen mode

32

What is a closure? Give an example

33

let x =  y = 7;
y= 10;
console.log(x);
console.log(y); 
Enter fullscreen mode Exit fullscreen mode

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);πŸ’Ž
Enter fullscreen mode Exit fullscreen mode

35

function* generator(num) {
  yield num;
  yield num * 10;
}
let result = generator(100);
console.log(πŸ’«);// 100
console.log(πŸ’«); //1000
Enter fullscreen mode Exit fullscreen mode

36

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

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);  
Enter fullscreen mode Exit fullscreen mode

39

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

Enter fullscreen mode Exit fullscreen mode

40

function🐻(i) { 
   let πŸ”’= function() {
     i++;
    };
    return πŸ”’; 
}
let 🍎 =  🐻(1000);
let 🍏 = 🐻(1)
🍎(); //?
🍏(); //?

Enter fullscreen mode Exit fullscreen mode

41

let πŸ‡ = new Set();
πŸ‡.add(1);
πŸ‡.add(5);
πŸ‡.add(1,5)
πŸ‡.add(1, 1000)
console.log(πŸ‡.size); // ⭐️
Enter fullscreen mode Exit fullscreen mode

42

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

Enter fullscreen mode Exit fullscreen mode

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

43

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

Enter fullscreen mode Exit fullscreen mode

44

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

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

Enter fullscreen mode Exit fullscreen mode

45

const animals  = [β€œπŸ¦Šβ€, β€œπŸΈβ€, β€œπŸΉβ€, β€œπŸ°β€];
animals.length = 10;
console.log(animals[0]); 
animals.length = 2;
console.log(animals[3]); 
Enter fullscreen mode Exit fullscreen mode

46

//(hint:https://0.30000000000000004.com/ ) :
⭐️console.log(0.1 + 0.2);
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

49

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

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

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

Enter fullscreen mode Exit fullscreen mode

50

//Complete the following fxn:

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

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

Enter fullscreen mode Exit fullscreen mode

51

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

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

Enter fullscreen mode Exit fullscreen mode

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)//[πŸ“, πŸ₯, πŸ₯,πŸ“];
Enter fullscreen mode Exit fullscreen mode

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");
Enter fullscreen mode Exit fullscreen mode

Top comments (0)