this.newFramework = ""; // empty string
if (this.newFramework)
{
console.log("This will not be logged.");
}
- **If `this.newFramework` is null, undefined, an empty string, 0, or NaN**: The condition evaluates to `false`, and the code inside the `if` block is not executed.
- **If `this.newFramework` is a non-empty string, a non-zero number, an object, or any other truthy value**: The condition evaluates to `true`, and the code inside the `if` block is executed.- **`localStorage` does not automatically clear its contents when the browser is closed.
** Data persists until explicitly removed.
- If you want data to be cleared when the browser or tab is closed, use **`sessionStorage`**, which only retains data for the duration of the session
// Storing a value
localStorage.setItem('username', 'john_doe');
// Retrieving a value
const username = localStorage.getItem('username');
console.log(username); // Output: john_doe
// Removing a value
localStorage.removeItem('username');
// Trying to retrieve the value again
const removedUsername = localStorage.getItem('username');
console.log(removedUsername); // Output: null
No comments:
Post a Comment