JSFiddle - React, Tailwind, and code Playground

by shyamh

HTML

<p>Test <code>localStorage</code> and <code>sessionStorage</code> capacity.</p>

<button id="run">Run</button>
<br/>
<div id="ls"></div>
<div id="ss"></div>

JavaScript

// a string of 1024 characters
long_string = "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234";


function run() {

    i = 0;
    try {
        while (true) {
            localStorage.setItem("_" + i, "1234567890");
            i += 1;
        }
    } catch (e) {
        $("#ls").html("Added ~" + (i * 1024) + " bytes of data to sessionStorage");
    }

    i = 0;
    try {
        while (true) {
            sessionStorage.setItem("_" + i, "1234567890");
            i += 1;
        }
    } catch (e) {
        $("#ss").html("Added ~" + (i * 1024) + " bytes of data to localStorage");
    }
}

$("#run").click(run);