JavaScript Fundamentals Before Learning React Educative Quiz Answers

Get JavaScript Fundamentals Before Learning React Educative Quiz Answers

After teaching React extensively (33.000+ students), be it online for a larger audience or on-site for companies transitioning to web development and React, I always come to the conclusion that React is all about JavaScript. Most of it boils down to JavaScript ES6 and beyond features and syntax, but also ternary operators, shorthand versions in the language, the ‘this’ object, JavaScript built-in functions (map, reduce, filter) or more general concepts such as composability, reusability, immutability or higher-order functions. While you don’t need necessarily to master all of these before starting with React, they will come up while practicing it and so to learn them will put you at a great advantage.

This course is my attempt to give you comprehensive JavaScript skills that will make your React journey smooth and straight-forward.

Enroll on Educative

Quiz 1: JavaScript Variables & Operators

Q1. You can add new properties to an instance object any time later after its creation. True or False?

  • True
  • False

Q2. The most recommended way of declaring a variable is using:

  • var
  • let
  • const
  • All of the above

Q3. Which of these are accessible throughout the code:

  • Constants
  • Local Variables
  • Global Variables
  • Both A and C

Q4. What will be the output of the following code snippet?

const student = {
  ID: '21',
  name: 'Jhon',
  GPA: '3.0',
};

const {GPA:n} = student;
console.log(n);
  • Jhon
  • 21
  • 3.0
  • All of above

Q5. Automatic type conversion is supported by JavaScript. Is this statement True or False?

  • True
  • False

Challenge 1: Write a JavaScript function expression

Rewrite the cube() function given using a ‘function expression’. It can be named or anonymous but remember to name the object (i.e., var etc) cube or your code won’t compile.

Solution:
var cube = function(n) {
  return n*n*n;
}

Challenge 2: Write a JavaScript arrow function

Rewrite the given square function using arrow functions. Again, remember to name it square or your code won’t compile.

Solution:
var square = n => n*n;

Challenge 3: Use the map() method

In the following, write a program using the map function​ that squares the numbers in the hidden given array called notSquared. It contains random integers.

Note:

  • Call the new array squared or your code won’t compile.
  • Make sure to replace your solution with ‘-1’ only – do not include variable declarations or any other syntax before squared.
Solution:
squared = notSquared.map( n => n*n );

Quiz 2: JavaScript Functions

Q1. A function passed into another function as an argument is called:

  • Arrow Function
  • Constructor Function
  • Callback Function
  • Promise

Q2. A function that returns an iterator using yeild keyword is called:

  • Constructor Function
  • Generator Function
  • Generator Function Expression
  • Declaration Function

Q3. What would the following code do?

render(){
   let users = [ 
  { 'name' : 'Elton Jhon', 'age' : 60 }, 
  { 'name' : 'Elvis Persley', 'age' : 50 }, 
  { 'name' : 'Kurt Cobain', 'age' : 24} 
];
   return (<div>
     {users.map(user => <p>{user.name}</p>)}
   </div>)
}
  • This code will generate a Syntax error
  • Display a list of all user names
  • Displays nothing
  • Displays all users’ name in the same line

Q4. What would this code do?

function coolFunction(val){
    return val? "Cool" : "Not Cool"; 
}

var val = true;
  • Nothing
  • Returns “Cool” or “Not Cool” based on the value of val
  • Always returns “Cool”
  • Always returns “Not Cool”

Q5. What would the following function do?

function myFunction(my_array){
    return my_array.filter(function(num, position)){                       
                                return my_array.indexOf(num) == position;
                         }
}
  • Generates an error
  • Remove duplicates from the array
  • Adds all the elements present in the array
  • None of above

Challenge 4: Create a JavaScript class

In the following coding challenge, write a class in JavaScript that describes a car with the properties colormodelengineCap (engine capacity), and registrationNum registration number and methods getColor()getModel()setColor(), and setModel(). Remember to use the exact spelling given here or your code won’t pass.

Solution:
class Car {
  constructor(color, model, engineCap, registrationNum) {
    this.color = color;
    this.model = model;
    this.engineCap = engineCap;
    this.registrationNum = registrationNum;
  }
  getColor() {
    return this.color;
  }
  
  getModel() {
    return this.model;
  }
  
  setColor(Color) {
    this.color = Color;
  }
  
  setModel(Model) {
    this.model = Model;
  }
}

Challenge 5: Fix the error

Solution:
let me = {
  firstname: "Robin",
  getName: function(){
    console.log(this.name);
  }
}

// You have to bind the function to the object because just assigning it to a var
// ... is equivalent to assigning a standalone function to a var
var getMyName = me.getName.bind(me);
getMyName();

Quiz 3: JavaScript Classes

Q1. In JavaScript, this keyword refers to:

  • the current object in main
  • the current object in the scope
  • the current object in the file
  • All of above

Q2. JavaScript classes are basically objects. Is this statement True or False?

  • True
  • False

Q3. ES6 does not support overriding. Is this statement True or False?

  • True
  • False

Q4. Explicit binding occurs when dot notation is used to invoke a function. Is this statement True or False?

  • True
  • False

Q5. When we use call() on a fuction, the type of binding that occurs is:

  • Implicit
  • Explicit
  • Both
  • None

Quiz 4: JavaScript Modules

Q1. Which of these scenarios best explain Modularity:

  • Function A should be entirely independent of Function B
  • If there are more than one classes in a file, split it!
  • All methods written inside class definition should be strongly related to the class
  • Both B and C

Q2. The intellisense suggested modules are actually dependencies that exist in:

  • index.js
  • package.json
  • modules.js
  • None of above

Q3. While importing a module in a file, we specify its path from:

  • Root Directory
  • Current Directory
  • We don’t. We just write the name of module
  • None of the above

Q4. The modules that are imported without using the path symbol are actually:

  • Public Libraries of your Project
  • Libraries written added within the same Project
  • Third Party Libraries
  • All of above

Q5. Which of the following keyword is used to rename the module while importing it

  • nameas
  • alias
  • as
  • namedas

Quiz 5: React

Q1. What is a React component in JavaScript?

  • A class
  • A function
  • An object
  • All of the above

Q2. There is a method in React component which is overidden to prevent updating the components. Which of the following is that method?

  • componentDidUpdate
  • shouldComponentUpdate
  • componentNotUpdate
  • componentShouldUpdate

Q3. The data is passed to a component through:

  • render()
  • setState()
  • Props
  • All of above

Q4. How would you write a JavaScript function inside JSX?

  • <p>{function()}</p>
  • <p>${function}</p>
  • <p>${function}$</p>
  • <p>{function}</p>

Q5. Calling setState method inside render() does not generate any errors. Is this statement True or False?

  • True
  • False

Q6. JSX is not a type-safe language. Is this statement True or False?

  • True
  • False

Q7. The main purpose of using lifecycle methods is:

  • To keep backups of all changes
  • To optimize the performance
  • To free the resources
  • None of the above

Q8. What happens when you make multiple setState() calls within a function?

  • React performs the operation the same number of times it is called
  • React gathers all states and performs the operation only once
  • The system hangs due to simultaneous setState calls
  • None of above

Q9. Can components refer to other components? Answer in yes or no.

  • Yes
  • No

Q10. The main focus of React is:

  • Model
  • View
  • Controller
  • All of the above

Q11. The div element that is defined inside a render method is an actual DOM element. Is this statement true or false?

  • True
  • False
Conclusion:

I hope this JavaScript Fundamentals Before Learning React 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. Required fields are marked *