Skip to content

Latest commit

 

History

History
61 lines (31 loc) · 2.04 KB

19-call-apply-bind-exercise.md

File metadata and controls

61 lines (31 loc) · 2.04 KB

Call/Apply/Bind Questions

Question 1

Write a function that uses the call method to print the name of an object.

Question 2

Write a function that uses the apply method to find the minimum value in an array of numbers.

Question 3

Write a function that uses the bind method to create a new function that always has a specific "this" value.

Question 4

Write a function that uses the call method to add two numbers together.

Question 5

Write a function that uses the apply method to concatenate two arrays.

Question 6

Write a function that uses the bind method to create a new function that multiplies a number by a specified value.

Question 7

Write a function that uses the call method to find the length of a string.

Question 8

Write a function that uses the apply method to find the sum of all numbers in an array.

Question 9

Write a function that uses the bind method to create a new function that logs a message with a specific prefix.

Question 10

Write a function that uses the call method to convert a string to uppercase.

Question 11

Create a function sum that takes in two numbers and returns their sum. Use call to invoke sum with an array [2, 3] as the context and log the result to the console.

Question 12

Create an object person with a property name set to your name. Create a function sayHello that logs "Hello, !". Use bind to create a new function sayHi that logs "Hi, !" and use it to greet yourself.

Question 13

Write a function greet that takes in a string name and logs "Hello, !". Use apply to pass in an array ["Alice"] as the context and invoke the function.

Question 14

Create a function multiply that takes in two numbers and returns their product. Use bind to create a new function double that always doubles its argument, and use it to multiply 5 by 2.

Question 15

Create a function square that takes in a number and returns its square. Use map and square to create a new array squares that contains the squares of the numbers in an array [1, 2, 3, 4, 5].