Engineer bro!

Wed Mar 16 2022 (6 months ago)

Engineer by mistake!

I am a software engineer by passion

25 MCQs of JavaScript | SET - 3

In this article, I have listed 25 javascript MCQs for you to practice. Comment your answer with proper justification.

Table of contents

Q1

function Car() {
  this.make = 'Lamborghini';
  return { make: 'Maserati' };
}

const myCar = new Car();
console.log(myCar.make);

Q2

(() => {
  let x = (y = 10);
})();

console.log(typeof x);
console.log(typeof y);

Q3

class Dog {
  constructor(name) {
    this.name = name;
  }
}

Dog.prototype.bark = function() {
  console.log(`Woof I am ${this.name}`);
};

const pet = new Dog('Mara');

pet.bark();

delete Dog.prototype.bark;

pet.bark();

Q4

const set = new Set([1, 1, 2, 3, 4]);

console.log(set);

Q5

// counter.js
let counter = 10;
export default counter;

// index.js
import myCounter from './counter';

myCounter += 1;

console.log(myCounter);

Q6

const name = 'Lydia';
age = 21;

console.log(delete name);
console.log(delete age);

Q7

const numbers = [1, 2, 3, 4, 5];
const [y] = numbers;

console.log(y);

Q8

const user = { name: 'Lydia', age: 21 };
const admin = { admin: true, ...user };

console.log(admin);

Q9

const person = { name: 'Lydia' };

Object.defineProperty(person, 'age', { value: 21 });

console.log(person);
console.log(Object.keys(person));

Q10

const settings = {
  username: 'lydiahallie',
  level: 19,
  health: 90,
};

const data = JSON.stringify(settings, ['level', 'health']);
console.log(data);

Q11

let num = 10;

const increaseNumber = () => num++;
const increasePassedNumber = number => number++;

const num1 = increaseNumber();
const num2 = increasePassedNumber(num1);

console.log(num1);
console.log(num2);

Q13

const value = { number: 10 };

const multiply = (x = { ...value }) => {
  console.log((x.number *= 2));
};

multiply();
multiply();
multiply(value);
multiply(value);

Q14

[1, 2, 3, 4].reduce((x, y) => console.log(x, y));

Q15 - With which constructor can we successfully extend the Dog class?

class Dog {
  constructor(name) {
    this.name = name;
  }
};

class Labrador extends Dog {
  // 1
  constructor(name, size) {
    this.size = size;
  }
  // 2
  constructor(name, size) {
    super(name);
    this.size = size;
  }
  // 3
  constructor(size) {
    super(name);
    this.size = size;
  }
  // 4
  constructor(name, size) {
    this.name = name;
    this.size = size;
  }

};

Q16

// index.js
console.log('running index.js');
import { sum } from './sum.js';
console.log(sum(1, 2));

// sum.js
console.log('running sum.js');
export const sum = (a, b) => a + b;

Q17

console.log(Number(2) === Number(2));
console.log(Boolean(false) === Boolean(false));
console.log(Symbol('foo') === Symbol('foo'));

Q18

const name = 'Lydia Hallie';
console.log(name.padStart(13));
console.log(name.padStart(2));

Q19

console.log('🥑' + '💻');

Q20 - How can we log the values that are commented out after the console.log statement?

function* startGame() {
  const answer = yield 'Do you love JavaScript?';
  if (answer !== 'Yes') {
    return "Oh wow... Guess we're gone here";
  }
  return 'JavaScript loves you back ❤️';
}

const game = startGame();
console.log(/* 1 */); // Do you love JavaScript?
console.log(/* 2 */); // JavaScript loves you back ❤️

Q21

console.log(String.raw`Hello\nworld`);

Q22

async function getData() {
  return await Promise.resolve('I made it!');
}

const data = getData();
console.log(data);

Q23

function addToList(item, list) {
  return list.push(item);
}

const result = addToList('apple', ['banana']);
console.log(result);

Q24

const box = { x: 10, y: 20 };

Object.freeze(box);

const shape = box;
shape.x = 100;

console.log(shape);

Q25

const { name: myName } = { name: 'Lydia' };

console.log(name);

Thank You ❤️

Software EngineeringNodeJsJavaScript

Comments (0)

Discussions (0)


© 2021 dsabyte. All rights reserved