Skip to content

Instantly share code, notes, and snippets.

@OlivierJM
Created July 14, 2024 10:47
Show Gist options
  • Save OlivierJM/38426e11a5031a17fa1c13ea94fa6b76 to your computer and use it in GitHub Desktop.
Save OlivierJM/38426e11a5031a17fa1c13ea94fa6b76 to your computer and use it in GitHub Desktop.
interview.md
  1. What is the output of the following code?
console.log(typeof NaN);

a) "undefined" b) "number" c) "NaN" d) "object"

  1. Which of the following is NOT a valid way to declare a variable in JavaScript? a) var x = 5; b) let y = 10; c) const z = 15; d) int w = 20;

  2. What will be the value of x after this code executes?

let x = 5;
x += "2";

a) 7 b) "52" c) 52 d) "7"

  1. Which of these Array methods does NOT modify the original array? a) push() b) pop() c) splice() d) slice()

  2. What is the output of this code?

const obj = {a: 1, b: 2};
const {a, c = 3} = obj;
console.log(c);

a) undefined b) 2 c) 3 d) ReferenceError

  1. What is the output of the following code?
console.log(typeof typeof 1);
  1. Will the following code produce an error? If not, what will it output?
let a = 1;
let b = 2;
[a, b] = [b, a];
console.log(a, b);
  1. Compare the following two code blocks. What will be the difference in their outputs?
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}

for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}
  1. What is the value of x after the following code executes?
let x = 10;
(function() {
  x = 20;
})();
  1. What is the output of the following code?
const arr = [1, 2, 3];
arr[10] = 10;
console.log(arr.length);
  1. What is the output of the following code?
function foo() {
  return {
    bar: "hello"
  };
}

function baz() {
  return
  {
    bar: "hello"
  };
}

console.log(foo());
console.log(baz());
  1. Explain the difference between the 2 code blocks
const ids = [1, 2, 3, 4, 5];
const endpoint = 'https://jsonplaceholder.typicode.com/posts';
for (const id of ids) {
  try {
    const response = await fetch(`${endpoint}/${id}`);
    await response.json();
  } catch (error) {
    console.error(error);
  }
}
const ids = [1, 2, 3, 4, 5];
const endpoint = 'https://jsonplaceholder.typicode.com/posts';
try {
  for (const id of ids) {
    const response = await fetch(`${endpoint}/${id}`);
    await response.json();
  }
} catch (error) {
  console.error(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment