Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
In this course, you’ll learn to write modern JavaScript from the ground up. But instead of going over every possible edge case, you’ll focus on the syntax that has a significant impact in your day-to-day work. As you review each construct, you’ll learn not just how to use it, but, more importantly, when to.
Your time is valuable, and this course, based on the Pragmatic Programmers’ book, Simplifying JavaScript, covers all the most important language features. And with 51 tips in total, you’ll be able to jump into and out of this course easily. Before you know it, you’ll be a productive and modern JavaScript developer.
Q1. What will be the output of the code given below?
const obj = {};
obj.name = "Mark";
console.log(obj);
{ name: 'Mark' }
// TypeError: Assignment to constant variable
{}
Q2. What will be the output of the code given below?
const value = 0;
for(let i=0; i<10; i++){
value += i;
}
console.log(value);
45
TypeError: Assignment to constant variable
0
10
Q3. Which of the following is true about the code given below?
1- var planet = "Mars";
2- const days = 365;
3- var value = 10;
4- if(value > 5) {
5- var planet = "Jupiter";
6- days = 1050;
7- }
8- console.log(planet);
9- console.log(days);
Mars
and line 9 displays 365
Mars
and line 9 displays 1050
Jupiter
and line 9 gives the error TypeError: Assignment to constant variable
Jupiter
and line 9 displays 1050
Q1. What will be the output of the code below?
let value=55;
let value=47;
console.log(value);
55
47
SyntaxError: Identifier 'value' has already been declared
Q2. What will be the output of the code below?
1- let value1 = 5;
2- function func() {
3- let value2 = 6;
4-
5- if (value2 > value1) {
6- let value3 = 9;
7- value2++;
8- }
9-
10- console.log(value1);
11- console.log(value2);
12- console.log(value3);
13- }
14-
15- func();
5
, line 11 displays 6
, and line 12 displays 9
undefined
, line 11 displays 6
, and line 12 displays 9
undefined
, line 11 displays 7
, and line 12 displays 9
5
, line 11 displays 7
, and line 12 gives the error ReferenceError: value3 is not defined
Q1. Study the code below. What does the following program do?
const people = [ { name: "John", age: 16 },
{ name: "Thomas", age: 19 },
{ name: "John", age: 20 },
{ name: "Jess", age: 18 },];
const func = (collection) => {return collection.filter((person) => person.name == 'John');}
people
arrayname
properties that have the value John
name
property with value John
age
of the objects that have the name
property with value John
Q1. What is the output of the following code?
function func1(arr1, arr2, n) {
let arr3 = [...arr2];
arr3.splice(n,0, ...arr1);
return arr3;
}
console.log(func1([1, 2, 3], [4, 5, 6], 1));
[ 1, 2, 3, 4, 5, 6]
[ 4, 5, 6, 1, 2, 3]
[ 4, 1, 2, 3, 5, 6 ]
[ 4, 6, 1, 5, 3, 2]
Q1. Given a collection of movies and a list of their directors, would you store the movie-director pairs in an object or an array?
Q2. Given a class of students, you want to list the rank of each student from the lowest to the highest. Should you use an array or object to store the student ranks?
Q1. What will be the output of the code given below?
var obj1 = { a: 5, b: 5, c: 5 };
var obj2 = { b: 20, c: 30 };
var obj3 = { a: 10 ,c: 40 };
var newobj = Object.assign({}, obj1, obj2, obj3);
console.log(newobj);
{ a: 5, b: 5, c: 5, b: 20, c: 30, a: 10 ,c: 40 }
{ a: 5, b: 5, c: 5 }
{ a: 10, b: 20, c: 40 }
{ a: 5, b: 20, c: 30 }
Q1. What will be the output of the code below?
let person1 = { name: 'Joey', age: '21' };
let person2 = { name: 'Rachel', age: '22' };
let persons = [ person1, person2 ];
let setJob = function( persons, index, job ) {
persons[ index ].job = job;
return persons;
}
setJob( [...persons], 0, 'Artist' );
console.log( persons);
[ { name: 'Joey', age: '21'}, { name: 'Rachel', email: '22' } ]
[ { name: 'Rachel', email: '22' }, { name: 'Joey', age: '21'} ]
[ { name: 'Joey', age: '21'}, { name: 'Rachel', email: '22', job: 'Artist' } ]
[ { name: 'Joey', age: '21', job: 'Artist' }, { name: 'Rachel', email: '22' } ]
Q1. What is the output of the code below?
const map = new Map();
const foods = { dinner: 'Curry', lunch: 'Sandwich', breakfast: 'Eggs' };
const normalfoods = {};
map.set(normalfoods, foods);
for (const [key] of map) {
console.log(map.get(key));
}
dinner lunch breakfast
'Curry' 'Sandwich' 'Eggs'
{ dinner: 'Curry', lunch: 'Sandwich', breakfast: 'Eggs' }
{}
Q1. What will be the output of the code below?
let map = new Map([
[1, 'Anne'],
[2, 'Joe'],
[3, 'Rachel'],
]);
let arr = [...map.keys()];
console.log(arr);
[ 1, 2, 3 ]
[ 'Anne', 'Joe', 'Rachel' ]
[[1, 'Anne'], [2, 'Joe'], [3, 'Rachel']]
Q2. What will be the output of the code below?
let names = new Map()
.set(18, 'Anne')
.set(25, 'Rachel')
.set(35, 'Joe');
const answer = [...names]
.filter(([k]) => k < 30)
console.log(answer);
[ [ 18, 'Anne' ], [ 25, 'Rachel' ], [ 35, 'Joe' ] ]
[ [ 18, 'Anne' ], [ 25, 'Rachel' ] ]
[18, 25, 35]
[Anne, Rachel, Joe]
Q1. What will be the output of the code below?
let arr = [5,5,5,7,6,2,3,8,8];
let uniqueElem = [...new Set(arr)];
console.log(uniqueElem);
[ 2, 3, 5, 6, 7, 8]
[ 5, 7, 6, 2, 3, 8 ]
[5, 5, 5, 7, 6, 2, 3, 8, 8]
[ 2, 3, 5, 5, 5, 6, 7, 8, 8]
Q2. What will be the output of the code below?
let ans = new Set([1, 1, 2, 2, 3, 5 ,8])
console.log([...ans].map(x => x * 2));
Q1. What will be the output of the following code?
var val1 = "20";
var val2 = 20;
console.log(val1 == val2);
true
false
Q2. What will be the output of the following code?
console.log(0 === false);
true
false
Q3. What will be the output of the following code?
var a = "0";
if(a == false){
console.log("Hello");
}else{
console.log("Bye");
}
Hello
Bye
Q1. What will be the output of the following code?
let price = 180;
let answer = (price < 50) ? "Cheap" :
(price < 100) ? "Economical" :
(price < 150) ? "Expensive" : "Overpriced" ;
console.log(answer);
Cheap
Economical
Expensive
Overpriced
Q1. Study the code below:
function multiplybyTwo(val) {
return val * 2;
}
For the function above, which of the options below shows the correct conversion to an arrow function?
var multiplybyTwo(val) => {val * 2}
var multiplybyTwo = val => return val * 2
var multiplybyTwo = val => val * 2
var multiplybyTwo => val * 2
Q1. Study the program below:
const double = (x) => {
return x*x;
}
const values = [2, 4, 6]
for (let i = 0; i < values.length; i++) {
double(values[i])
}
Which lines of the code below are equivalent to the for loop in the example above?
const newArray = values.map((value) => double(value))
const newArray = values.map(double)
values.forEach((value) => {
double(value)
})
Q1. What does the following program do?
const arr = [{name: 'Bryan', age: '21'}, {name: 'Allen', age: '22'}]
const ans = arr.map(obj => {
obj.name = obj.name + 'a'
obj.hobby = 'sports'
return obj;
})
console.log(ans)
a
at the end of the name
valuehobby
property to each objecta
at the end of the name
value and adds a hobby
property to the first object in the arraya
at the end of the name
value and adds a hobby
property to each object in the arrayQ1. What will be the output of the following code?
const students = [
{
name: 'mark',
marks: 40
},
{
name: 'bill',
marks: 95
},
{
name: 'steve',
marks: 60
},
];
students.filter(student => student.marks > 50)
.map(student => student.name.toUpperCase())
.forEach(student => console.log(`${student} passed`));
mark passed
bill passed
steve passed
bill passed
steve passed
STEVE passed
BILL passed
BILL passed
STEVE passed
Q1. What will be the output of the following code?
const func = (string) => string.split('').reduce((rev, char) => char + rev, '')
console.log(func("hello"));
h e l l o
hlo
ello
olleh
Q1. What will be the output of the following code?
function sumValues(val1, val2 = 10, val3 = 15) {
return val1 + val2 + val3;
}
console.log(sumValues(20,undefined,3));
Q1. Which of the following is the correct way of destructuring name
in the object give below?
let person = {
name: {
first: 'Robin',
last: 'Doe'
},
age: 20,
country: 'USA'
}
let {
first,
last
} = name
let {
first,
last
} = person
let {
firstName: first,
lastName: last
} = name
let {
name: {
first: firstName,
last: lastName
}
} = person;
Q1. What will be the output of the code below?
const func = (val1, val2, val3, ...args) => {
const res1 = args.map(val => val*2);
const res2 = res1.reduce((number, acc) => number += acc);
const res3 = val1 + val2 + val3 + res2;
return res3;
}
console.log(func(1,2,3,4,5));
Q1. What will be the output of the following code?
const person = {
name: 'Alex',
age: '20',
major : 'CS',
gpa: '3.3',
job: 'Developer',
sport: 'tennis',
};
const getCredentials = ({major, gpa , job }) => ({ credentials: `${major} ${gpa} ${job}` });
console.log(getCredentials(person));
{ credentials: 'CS 3.3 Developer' }
credentials: 'CS 3.3 Developer'
CS 3.3 Developer
Q2. The two functions in the code below are equivalent. Is this statement true or false?
function multiply(a,b,c){
return a*b*c;
}
const multiplyArrow = val1 => val2 => val3 => val1*val2*val3;
Q1. multiply
is a currying function. Is this statement true or false?
const multiply = (a , b) => a * b
Q2. What will be the output of the following program?
let arr = [1,2,3,4,5,6,7,8]
const func = f1 => f2 => arr => arr.filter(f1).map(f2)
const isEven = val => val%2 === 0;
const double = val => val*2;
console.log(func(isEven)(double)(arr));
[ 2, 4, 6, 8]
[ 4, 8, 12, 16 ]
[ 2, 4, 6, 8, 10, 12, 14, 16]
[ 1, 3, 5, 7]
Q1. What will be the output of the following code?
class Vehicle{
constructor(){
this.color = "Red";
}
}
class Car extends Vehicle{
constructor(){
super();
this.color = "Blue";
}
}
var car = new Car();
console.log(car.color);
Red
Blue
undefined
Q1. Study the code below:
1- function Person(name, age) {
2- this.name = name;
3- this.age = age;
4- }
5-
6- Person.getName = function () {
7- return `${this.name}.`;
8- };
Line 6 adds the getName
function to the prototype of Person
. True or False?
Q1. Which of the following is true about the generator given below?
function* nums() {
let val = 2;
while (true) {
yield val;
val = val + 1
}
}
Q2. What will the following code yield?
function* gen() {
let curr = 0;
let next = 1;
while(true) {
yield curr;
let num = curr + next;
curr = next;
next = num;
}
}
let iter = gen();
console.log(iter.next().value);
console.log(iter.next().value);
console.log(iter.next().value);
console.log(iter.next().value);
console.log(iter.next().value);
Q1. setTimeout()
runs code asynchronously in JavaScript. True or false?
Q2. What will be the output of the code below?
var multiply = function(num1, num2) {
return new Promise((resolve,reject) => {
var product = num1 * num2;
if (product) {
resolve(product);
}
else {
reject(Error("Could not multiply the values!"));
}
});
};
multiply(2,"x")
.then((data) => {console.log(data)})
.catch((error) => {console.log(error)})
4
Error: Could not multiply the values!
2x
Q3. What will be the output of the code below?
var multiply = function(num1, num2) {
return new Promise((resolve,reject) => {
var product = num1 * num2;
if (product) {
resolve(product);
}
else {
reject(Error("Could not multiply the values!"));
}
});
};
var double = function(val){
return Promise.resolve(val*2)
}
multiply(2,2)
.then((data) => double(data))
.then((data) => console.log(data))
.catch((error) => {console.log(error)})
2
4
8
Error: Could not multiply the values!
Q1. What will be the output of the code below?
const add = function(x,y){
return new Promise((resolve,reject) => {
resolve(x+y);
})
}
const multiply = function(x,y){
return new Promise((resolve,reject) => {
resolve(x*y);
})
}
async function f() {
let result1 = await add(2,5);
let result2 = await multiply(9,4);
return result1 + result2;
}
f()
.then((data) => console.log(data))
.catch((data) => console.log(data))
43
7
36
I hope this Simplifying JavaScript: A Handy Guide for Software Engineers Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.
This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.
Keep Learning!
More Coding Solutions >>