Codelab Editor
Free Online HTML Editor
Run
Learn JSON
<!DOCTYPE html> <html> <head> <style> body { padding: 10px; background: #fdfdfd; font-family: sans-serif; } .user-card { display: none; max-width: 340px; padding: 16px; border: 1px solid #ccc; border-radius: 12px; background-color: #f5f5f5; margin-top: 20px; } .user-card h3 { margin: 0 0 10px; font-size: 20px; } .user-card p { margin: 6px 0; } button { margin-right: 10px; padding: 8px 16px; border: none; background-color: #0088cc; color: white; border-radius: 6px; cursor: pointer; } button:hover { background-color: #006fa3; } </style> </head> <body> <h2>Parsing and Restoring Functions from JSON</h2> <p>Click below to parse a JSON string that includes a function as a string and restore it using <code>eval</code>.</p> <button onclick="loadCalculator()">Parse Calculator</button> <div class="user-card" id="calcCard"> <h3 id="calcName"></h3> <p><strong>Compute 6 × 7 =</strong> <span id="calcResult"></span></p> <p><strong>Type:</strong> <span id="typeCheck"></span></p> </div> <script> function loadCalculator() { const jsonWithFunc = '{"name":"Calculator","compute":"(x, y) => x * y"}'; const parsed = JSON.parse(jsonWithFunc); // Restore the function from string parsed.compute = eval(parsed.compute); const result = parsed.compute(6, 7); document.getElementById('calcName').textContent = parsed.name; document.getElementById('calcResult').textContent = result; document.getElementById('typeCheck').textContent = typeof parsed.compute; document.getElementById('calcCard').style.display = 'block'; } </script> </body> </html>
Editor Commands
Ctrl
F
Find
Ctrl
G
Find Next
Ctrl
⇧
G
Find Previous
Ctrl
⇧
F
Find & Replace
Ctrl
]
Indent Code Right
Ctrl
[
Indent Code Left
⇧
Tab
Auto Indent Code
Ctrl
/
Line Comment
Ctrl
Alt
/
Block Comment
TutsInsider Actions
Alt
S
Run Code
Ctrl
C
Copy Editor Code
Ctrl
A
Select All Editor Code
Ctrl
S
Save/Download
Ctrl
Alt
X
Rotate
Ctrl
Alt
T
Switch Theme
Ctrl
⇧
C
Open Console
Esc
Close Console