I stumble upon below code of arrow function in a book "Getting Started with Angular, Second Edition".
let isPrime: (n: number) => boolean = n => {
// body
};
I want to confirm correctness of this breakdown.
let isPrime= function name "isPrime"(n: number)= input parameter number "n"=> boolean= arrow function to check boolean (a place to put the logic)=n= i don't get this part. does this mean if i put "logic to find prime number in third step" and true, you get "n" that satisfy my logic?=> {}= i can put return or other logic here for final process.
The last question is how many arrow functions is too much for chaining or curring?
I believe @Fenton give clear explanation for my understanding.
@Sebastien gives me answer that make me realise my wrong interpretation to arrow function ; equal and arrow sign doesn't always point to function, and can represent datatype too.
below is combined version of my accepted answer.
Types
Now let's describe the types for this function, which are that is takes in a number, and gives back a boolean.
//correct usage : return boolean
let isPrime: (n: number) => boolean = n => {
// body
return true
};
//incorrect usage
let isPrime: (n: number) => boolean = n => {
// body
return "wrong"
};
Simple
I suppose that I would write it as below, unless I had a good reason to use an arrow function!
//correct usage : return boolean
function isPrime(n: number): boolean {
// body
return true;
}
//incorrect usage
function isPrime(n: number): boolean {
// body
return "wrong";
}
My final test is like this.
let isRightLogic: (n: number) => { host: boolean } = n => {
return { host: true };
}
console.log(isRightLogic(1)); // always return true but you get the idea.