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)