Simplifying JavaScript: A Handy Guide for Software Engineers Educative Quiz Answers

Get Simplifying JavaScript: A Handy Guide for Software Engineers Educative Quiz Answers

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.

Enroll on Educative

Quiz 1: Tip 1: Signal Unchanging Values With const

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
  • {}
  • None of the above

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);
  • Line 8 displays Mars and line 9 displays 365
  • Line 8 displays Mars and line 9 displays 1050
  • Line 8 displays Jupiter and line 9 gives the error TypeError: Assignment to constant variable
  • Line 8 displays Jupiter and line 9 displays 1050

Quiz 2: Tip 2: Reduce Scope Conflicts with let and const

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
  • None of the above

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();
  • Line 10 displays 5, line 11 displays 6, and line 12 displays 9
  • Line 10 displays undefined, line 11 displays 6, and line 12 displays 9
  • Line 10 displays undefined, line 11 displays 7, and line 12 displays 9
  • Line 10 displays 5, line 11 displays 7, and line 12 gives the error ReferenceError: value3 is not defined

Quiz 3: Tip 5: Create Flexible Collections with Arrays

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');}
  • Returns all the objects in the people array
  • Returns those name properties that have the value John
  • Returns the objects that have the name property with value John
  • Returns the age of the objects that have the name property with value John

Quiz 4: Tip 7: Mold Arrays with the Spread Operator

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]

Quiz 5: Tip 10: Use Objects for Static Key-Value Lookups

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?

  • Array
  • Object

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?

  • Array
  • Object

Quiz 6: Tip 11: Create Objects Without Mutations Using Object.assign()

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 }

Quiz 7: Tip 12: Update Information with Object Spread

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' } ]

Quiz 8: Tip 13: Update Key-Value Data Clearly with Maps

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' }
  • {}

Quiz 9: Tip 14: Iterating over Key-Value Data with Map & Spread Operator

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']]
  • None of the above

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]

Quiz 10: Tip 16: Keep Unique Values with Set

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));        
  • [ 1, 2, 3, 5, 8 ]
  • [2, 2, 4, 4, 6, 10, 16, 16]
  • [ 2, 4, 6, 10, 16 ]
  • Error

Quiz 11: Tip 17: Shorten Conditionals with Falsy Values

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
  • Error
  • None of the above

Quiz 12: Tip 18: Check Data Quickly with the Ternary Operator

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

Quiz 13: Tip 20: Simplify Looping with Arrow Functions

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?

  • Code 1
var multiplybyTwo(val) => {val * 2}
  • Code 2
var multiplybyTwo = val => return val * 2
  • Code 3
var multiplybyTwo = val => val * 2
  • Code 4
var multiplybyTwo => val * 2

Quiz 14: Tip 21: Write Shorter Loops with Array Methods

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?

  • Code 1
const newArray = values.map((value) => double(value))
  • Code 2
const newArray = values.map(double)
  • Code 3
values.forEach((value) => {
  double(value)
})
  • All of the above

Quiz 15: Tip 22: Create Arrays of a Similar Size with map()

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)
  • Appends an a at the end of the name value
  • Adds a hobby property to each object
  • Appends an a at the end of the name value and adds a hobby property to the first object in the array
  • Appends an a at the end of the name value and adds a hobby property to each object in the array

Quiz 16: Tip 25: Combine Methods with Chaining

Q1. 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

Quiz 17: Tip 26: Transform Array Data with reduce()

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

Quiz 18: Tip 28: Create Default Parameters

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));
  • 45
  • 33
  • 23
  • 35

Quiz 19: Tip 29: Access Object Properties with Destructuring

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' 
}
  • Code 1
let {
      first, 
      last
} = name
  • Code 2
let {
      first, 
      last
} = person
  • Code 3
let {
      firstName: first, 
      lastName: last
} = name
  • Code 4
let {
  name: {
     first: firstName,
     last: lastName
  }
} = person;

Quiz 20: Tip 31: Passing Variable Number of Arguments with Rest Operator

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));
  • 15
  • 20
  • 24
  • 29

Quiz 21: Tip 33: Reduce Complexity with Arrow Functions

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
  • Error

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;
  • True
  • False

Quiz 22: Tip 35: Combine Currying & Array Methods for Partial Application

Q1. multiply is a currying function. Is this statement true or false?

const multiply = (a , b) => a * b
  • True
  • False

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]

Quiz 23: Tip 38: Share Methods with Inheritance

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
  • Error

Quiz 24: Tip 39: Extend Existing Prototypes with Class

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?

  • True
  • False

Quiz 25: Tip 41: Create Iterable Properties with Generators

Q1. Which of the following is true about the generator given below?

function* nums() {
  let val = 2;
  while (true) {
    yield val;
    val = val + 1
  }
}
  • It can yield only two values
  • It cannot yield any values
  • It can yield infinite values
  • It will give an error when run

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); 
  • A random sequence of four numbers
  • The fibonacci sequence 0,1,1,2,3
  • The sequence 0,1,2,3,4
  • Error

Quiz 26: Tip 43: Retrieve Data Asynchronously with Promises

Q1. setTimeout() runs code asynchronously in JavaScript. True or false?

  • True
  • 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
  • None of the above

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!

Quiz 27: Tip 44: Create Clean Functions with Async/Await

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
  • Error
Conclusion:

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 >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.