This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 👍 ✔ originally posted on: | |
// https://dirask.com/posts/10Wwaj | |
// we can run this code online under above link ☘ | |
// | |
<!doctype html> | |
<html> | |
<body> | |
<div> | |
<img id="image" style="border: 1px solid silver; width: 320px; height: 240px" /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This object contains a string value that in contains a single quote, | |
// a double quote, a backtick, and a backslash. | |
const data = { foo: `a'b"c\`d\\e` }; | |
// Turn the data into its JSON-stringified form. | |
const json = JSON.stringify(data); | |
// Now, we want to insert the data into a script body as a JavaScript | |
// string literal per https://v8.dev/blog/cost-of-javascript-2019#json, | |
// escaping special characters like `"` in the data. |