can anyone explain me this (func(num)) and this also num => num % 2 === 0
function findElement(arr, func) {
let num = 0
if(func(num)){
return num
}
}
findElement([1, 2, 3, 4], num => num % 2 === 0);
console.log(findElement([1, 2, 3, 4],2))
can anyone explain me this (func(num)) and this also num => num % 2 === 0
function findElement(arr, func) {
let num = 0
if(func(num)){
return num
}
}
findElement([1, 2, 3, 4], num => num % 2 === 0);
console.log(findElement([1, 2, 3, 4],2))
num => num % 2 === 0
That’s an arrow-function. It’s a short way to write a function in JS - you got the input on the left num
and the output on the right num % 2 === 0
.
So findElement
is called by giving it this arrow-function as definition for func
(second argument) and within findElement
, the provided arrow-function is now named func
and is called with num
like a normal function.
Thankyou very much jagaya
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.