Returning Boolean Values from Functions in JavaScript

·

1 min read

Hello everyone hope everyone is doing well. My name is Surya L, the purpose of this blog is to teach all about Returning Boolean Values from Functions in JavaScript.

Returning Boolean Values from Functions

Screenshot (215).png You may Read Equality Operator ☝️that all comparison operators return a Boolean true or false value.

Sometimes people use an if/else statement to do a comparison, like this:

function isEqual(a, b) {
  if (a === b) {
    return true;
  } else {
    return false;
  }
}

But there's a better way to do this. Since === returns true or false, we can return the result of the comparison:

function isEqual(a, b) {
  return a === b;
}

Example:

function isLess(a, b) {
 return a<b;
}

isLess(10, 15);

In the above code, true is returned if the condition is met, otherwise false is returned.

Credits: I learned this topics in FreeCodeCamp which I explained in minified version

Thanks for reading the blog. Do let me know what you think about it.

📫 How to reach me: Linkedin Showwcase Twitter Blog GitHub Contact Me