Engineer bro!
Mon Nov 15 2021 (2 years ago)
Engineer by mistake!
I am a software engineer by passion
In this article, I have listed 25 javascript MCQs for you to practice. Comment your answer with proper justification.
function sayHi() {
console.log(name);
console.log(age);
var name = 'Lydia';
let age = 21;
}
sayHi();
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 1);
}
const shape = {
radius: 10,
diameter() {
return this.radius * 2;
},
perimeter: () => 2 * Math.PI * this.radius,
};
console.log(shape.diameter());
console.log(shape.perimeter());
console.log(+true);
console.log(!'Lydia');
const bird = {
size: 'small',
};
const mouse = {
name: 'Mickey',
small: true,
};
A: mouse.bird.size
is not valid
B: mouse[bird.size]
is not valid
C: mouse[bird["size"]]
is not valid
D: All of them are valid
let c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
let c = { greeting: 'Hey!' };
let d;
d = c;
c.greeting = 'Hello';
console.log(d.greeting);
let a = 3;
let b = new Number(3);
let c = 3;
console.log(a == b);
console.log(a === b);
console.log(b === c);
class Chameleon {
static colorChange(newColor) {
this.newColor = newColor;
return this.newColor;
}
constructor({ newColor = 'green' } = {}) {
this.newColor = newColor;
}
}
const freddie = new Chameleon({ newColor: 'purple' });
console.log(freddie.colorChange('orange'));
let greeting;
greetign = {}; // Typo!
console.log(greetign);
function bark() {
console.log('Woof!');
}
bark.animal = 'dog';
Is there any error, mention the reason of your answer
function bark() {
console.log('Woof!');
}
bark.animal = 'dog';
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const member = new Person('Lydia', 'Hallie');
Person.getFullName = function() {
return `${this.firstName} ${this.lastName}`;
};
console.log(member.getFullName());
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
const lydia = new Person('Lydia', 'Hallie');
const sarah = Person('Sarah', 'Smith');
console.log(lydia);
console.log(sarah);
function Person(firstName, lastName) {
console.log(this);
this.firstName = firstName;
this.lastName = lastName;
}
const member1 = new Person("Lydia", "Hallie");
const member2 = Person("Lydia", "Hallie");
// mention the reason
Target > Capturing > Bubbling
Bubbling > Target > Capturing
Target > Bubbling > Capturing
Capturing > Target > Bubbling
true
false
function sum(a, b) {
return a + b;
}
sum(1, '2');
let number = 0;
console.log(number++);
console.log(++number);
console.log(number);
function getPersonInfo(one, two, three) {
console.log(one);
console.log(two);
console.log(three);
}
const person = 'Lydia';
const age = 21;
getPersonInfo`${person} is ${age} years old`;
function checkAge(data) {
if (data === { age: 18 }) {
console.log('You are an adult!');
} else if (data == { age: 18 }) {
console.log('You are still an adult.');
} else {
console.log(`Hmm.. You don't have an age I guess`);
}
}
checkAge({ age: 18 });
function getAge(...args) {
console.log(typeof args);
}
getAge(21);
function getAge() {
'use strict';
age = 21;
console.log(age);
}
getAge();
const sum = eval('10*10+5');
sessionStorage.setItem('cool_secret', 123);
Forever, the data doesn't get lost.
When the user closes the tab.
When the user closes the entire browser, not only the tab.
When the user shuts off their computer.
var num = 8;
var num = 10;
console.log(num);
const obj = { 1: 'a', 2: 'b', 3: 'c' };
const set = new Set([1, 2, 3, 4, 5]);
obj.hasOwnProperty('1');
obj.hasOwnProperty(1);
set.has('1');
set.has(1);
const obj = { a: 'one', b: 'two', a: 'three' };
console.log(obj);
true
false
for (let i = 1; i < 5; i++) {
if (i === 3) continue;
console.log(i);
}
© 2021 dsabyte. All rights reserved