Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading