This function is supposed to return an object, however, the construction used below is unfamiliar to me. How does this function work?
function expect(value) {
return {
toBe: exp => console.log(success)
}
}
This is a standard JavaScript function:
function(parameter1, parameter2) {
return returnVal;
}
But the object that is being returned looks like this:
{
toBe: exp => console.log(success)
}
Which is an object containing an ES6 arrow function, and can be alternatively expressed like so (a direct translation to an ES5 function):
{
toBe: function(exp) {
return console.log(success);
}
}
Read here for more information on ES6 arrow function notation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With