compare equality function

this will check if two values are exactly equal
function is_equal(a, b) {
  if (a === b) {
    return "Equal";
  }
  return "Not Equal";
}
console.log(is_equal(1,1));
console.log(is_equal(1,'1'));

// you can also change this function to return true and false, but this may be just as long as actually doing the if(a === b) manually.
function is_equal_bool(a, b) {
  if (a === b) {
    return true;
  }
  return false;
}

if(is_equal_bool(1, 1)) {
  console.log('1 and 1 is exactly equal');
}

// vs -- probably better to just use the ===
if( 1 === 1 ) {
  console.log('1 and 1 is exactly equal');
} else {
  console.log('1 and 1 is NOT exactly equal');
}

Other Items in javascript
Page Views

This page has been viewed 307 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹

Random Quote
For a long time it had seemed to me that life was about to begin - real life. But there was always some obstacle in the way, something to be gotten through first, some unfinished business, time still to be served, or a debt to be paid. Then life would begin. At last it dawned on me that these obstacles were my life.
Alfred D. Souza