'Cannot compare null
const LOCALE_STORAGE_LIST_KEY = 'task.lists'
const LOCALE_STORAGE_SELECTED_LIST_ID_KEY = 'task.selectedListId'
let lists = JSON.parse(localStorage.getItem(LOCALE_STORAGE_LIST_KEY)) || []
let selectedListId = localStorage.getItem(LOCALE_STORAGE_SELECTED_LIST_ID_KEY)
console.log(selectedListId); null script.js:19:9
console.log(selectedListId == null); false script.js:20:9
console.log(null == null); true script.js:21:9
console.log(typeof selectedListId); string script.js:22:9
console.log(typeof null); object script.js:23:9
I need to compare selectedListId with null and get true in if statement!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
