Skip to main content

Posts

Showing posts with the label javascript

Truthy value & Falsy value in JavaScript

 JavaScript uses type-conversion to any value in a boolean context .  So, the first question is what is the boolean context ? A boolean context refers to that piece of code where we only consider true/false as output. For example, parentheses of if  is a boolean context. Now, what is falsy or truthy mean? Falsy is a value that is considered False when encountered in a boolean context and Truthy value is considered True when encountered in a boolean context. There are 6 falsy values in JavaScript - undefined, null, NaN, "", 0, false. And rest of the values in a boolean context are considered as truthy. Happy learning! GitHub:  https://github.com/mukitul/javascript-es6-rxjs/blob/main/src/es6-practice/truthy-and-falsy.js Reference: https://www.freecodecamp.org/news/falsy-values-in-javascript/

Double (==) equal and Triple (===) equal sign - how it works on JavaScript | a brief explanation!

 In JavaScript, we may come across double equal (==) and triple equal (===) sign while checking the equality of two variables' values. But why two different operators are there for the same operation of equality check? What do they actually mean? You will find the answers in this blog. 1. How  ==  ( double equal ) works Double equal does the loose equality check. It checks the value equality only. It converts the type of the variables to match each other. Some common examples of double equal (==) check of two variables x and y are given below in tabular form - x y x==y undefined undefined / null true undefined true / false / NaN / 0 / 17 / 'string' false null true / false / NaN / 0 / 12 / 'string' false null null / undefined true NaN any-value false new String("mukitul") "mukitul" true {...