Is "foo === bar" equal to "if (foo === bar) {return true}"?

I know this question falls in the realm of "basics", however I’d like to understand the inner workings of the language.

My question is:
Do operators ‘return’ the expression’s value by default after evaluation?
‘return’ as in if we were to write:

//some operation using == < > etc...
return result;

>Solution :

There is a slight difference.

foo===bar does not return anything, it only calculates a boolean value.

You can combine this with a return statement, foo===bar to return true if foo == bar, and false otherwise.

if (foo === bar){return true} ONLY returns true if the two are equal, it would return nothing if foo does not equal bar.

Leave a Reply