What is the a implicit return and how is it different from the non implicit return? Also, are there other types of returns we learn in JavaScript?

What is the a implicit return and how is it different from the non implicit return? Also, are there other types of returns we learn in JavaScript?

The opposite of implicit is explicit.

Explicit returns are really the bread and butter of most programming languages (including javascript). I don’t think I’ve ever written an implicit return other than for this example… but i see a lot of good use cases for it.

I think implicit returns in js have to do with arrow functions:

let func = x => x + x;                  
// implicit return (because no brackets for the function code)
func(5)
//returns 10

let func2 = (x, y) => { return x - y; }; 
// notice the brackets, and the explicit statement of return

func2(5,4)
//returns 1
2 Likes

Indeed. I think the idea is similar to Python’s lambda functions.

2 Likes

Thank you for translating it for me hahaha. Ahem…

2 Likes

So, can we just say an implicit return is implied? Meaning you don’t write the word return.

To say implicit is to mean implied. For “it’s an implicit return” you could also say “the return is implied”. It would be redundant to say “the implicit return is implied”.

ty thats what i meant. yours is much clearer.

perhaps you could help me with a question. How do create the javascript for a button that logs the current time and keeps track until you click the button again. I want to create a sleep debt button. the button would say sleep and change to wake when clicked and viceversa.