Solve - localStorage is not defined Error in JavaScript-Code Examples

Radu TM

Solve - localStorage is not defined Error in JavaScript

JavaScript by Radu TM June 21, 2022

// 1. Check if localStorage is available:

if (typeof localStorage === "undefined") {
  // 2. If not, provide a message to the user:
  console.log("Sorry, your browser does not support localStorage.");
} else {
  // 3. Otherwise, proceed as normal:
  console.log("localStorage is available!");
}

0

26.757

Solve - localStorage is not defined Error in JavaScript

JavaScript by Radu TM June 21, 2022

//localStorage is not defined error in JavaScript
const storage = window.localStorage;

// check if localStorage is available

if (storage) {
  // localStorage is available
} else {
  // localStorage is not available
}

0

26.757

Related JavaScript Queries

Latest JavaScript Queries

Explore code examples by categories