This means we compare two values after converting them to a common type. In JavaScript, a double equals tests for loose equality and preforms type coercion. null != undefinedīut, and this may surprise you, null loosely equals undefined. Thus, it makes sense that null does not strictly equal undefined. If you’re not familiar with data types in JavaScript, I recommend reading my previous article: JavaScript Data Types ExplainedĪs you can see so far, null and undefined are different, but share some similarities. This has occurred since the beginning of JavaScript and is generally regarded as a mistake in the original JavaScript implementation. Interestingly enough, when using typeof to test null, it returns object: let a = null let b console.log(typeof a) // object console.log(typeof b) // undefined Here is a full list:Īll other values in JavaScript are objects (objects, functions, arrays, etc.). Both null and undefined are primitive values. Triple EqualsĪlso in JavaScript, there are six primitive values. If you’re not familiar with truthy/falsy values in JavaScript, I recommend reading my previous article: JavaScript - Double Equals vs. Here’s a full list:Īny other value in JavaScript is considered truthy. Both null and undefined are two of the six falsy values. In JavaScript there are only six falsy values.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |