DEV Community

christosmito
christosmito

Posted on

Bottom values in Javascript

Javascript has two bottom values. The null and undefined values are considered javascript's bottom values that indicate the absence of a value. In addition, these values are the only values in javascript that are not object. Attempting to get a property from them raises an exception. Even though the null is a well known value in other languages and it is commonly used, in javascript it is considered best practice to use undefined in most cases. First let's see the only case that we can use null instead of undefined. Using Object.Create(null) in order to create a new empty object. So, why we should use undefined? Because javascript itself uses this value. If you define a non-initialize variable with let and var their values are undefined. If you do not pass enough arguments into a function, if you request a property from an object that lacks that property and if you get an element of an array that the array lacks, javascript gives undefined. We can make better programs if we eliminate one of them not from the language 😛 but from our programs

Top comments (0)