Codelab Editor
Free Online HTML Editor
Run
Learn JSON
<!DOCTYPE html> <html> <head> <style> body { padding: 10px; background: #fdfdfd; font-family: sans-serif; } pre { background-color: #eee; padding: 10px; border-radius: 6px; overflow-x: auto; display: none; } button { margin-right: 10px; padding: 8px 16px; border: none; background-color: #0088cc; color: white; border-radius: 6px; cursor: pointer; } button:hover { background-color: #006fa3; } h3 { margin-top: 20px; } </style> </head> <body> <h2>Serializing Functions with JSON.stringify()</h2> <p>Click the button to serialize an object containing a function using <kbd>JSON.stringify()</kbd>.</p> <button onclick="serializeFunction()">Serialize Function</button> <h3 id="objectTitle" style="display:none;">Original Object</h3> <pre id="objectOutput"><code></code></pre> <h3 id="jsonTitle" style="display:none;">JSON String</h3> <pre id="jsonOutput"><code></code></pre> <script> function serializeFunction() { const obj = { name: "Widget", calculate: function () { return 42; } }; const jsonString = JSON.stringify(obj); document.getElementById('objectOutput').style.display = 'block'; document.getElementById('jsonOutput').style.display = 'block'; document.getElementById('objectTitle').style.display = 'block'; document.getElementById('jsonTitle').style.display = 'block'; document.querySelector('#objectOutput code').textContent = `const obj = {n name: "Widget",n calculate: function () {n return 42;n }n};`; document.querySelector('#jsonOutput code').textContent = jsonString; } </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