There are two most important terms to understand when you execute some code based on an “if else” statement. Truthy and Falsy value.
Truthy value: Data types that return true by default are called truthy.
False value: Data types that return false by default are called falsy
- All values are truthy except these values
- +0 or -0
- BigInt zero (0n)
- Empty String (“”)
- null, undefined, and NaN
For example below this code we are performing a Linear search. But when I apply a condition for “value not found” I have a complexity for array index 0. I solved this in my way. But there are several ways to solve this.