Https://www.codecademy.com/paths/web-development/tracks/getting-started-with-javascript/modules/code-challenge-javascript-fundamentals/lessons/javascript-fundamentals-code-challenge/exercises/truthy-or-falsy

Hello just need a wee talking to, i am confused as to why i needed to put value in the function parameter? i thought that i only needed to do it for the if"()". thanks in advance.

It’s because the => (arrow function expression) requires it syntactically.

Consider that here you are writing a function, which at a minimum needs 3 things in declaration:

  • a key term that says its a function (in this case =>)
  • a name (truthyOrFalsy here)
  • and a parameter holder (), the parameter can be empty or hold as many parameters as you need.

Another way to declare this same function is

function truthyOrFalsy(value) {
   //code
}

so for this particular case because its a boolean it needs something representing ‘value’ there?

A function is simple a block of code that does something. It can take in parameters or not.

In this case, this function’s role is to tell you whether anything you input into is is truthy or falsy.

so for this particular case because its a boolean it needs something representing ‘value’ there?

Any time we want to input a parameter into a function, we need a placeholder variable name, it can be anything but it should be something that reflects it’s meaning.

function eat(food) {
    console.log(`I ate some ${food}`);
}

eat("banana");
//output: I ate some banana

BUT this code will also work like this, it’s just not good practice

function eat(paper) {
    console.log(`I ate some ${paper}`);
}

eat("banana");
//output: I ate some banana
2 Likes

thank you. Very helpful. understanding JS logic is a bit challenging for me but ill get it. Thanks 100!