Dec 10, 2022
Cute... if this was 2008. Variables for nothing, tons of lines for nothing. Seriously, Object.assign is your friend.
document.body.appendChild(
Object.assign(
document.createElement("script"),
{
async : true,
onerror : () => {
console.log("Error occurred while loading script");
},
onload : () => {
console.log("Script loaded successfuly");
document.getElementById('box').textContent = "The script has loaded.";
},
src : "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"
}
)
);
No variables to worry about scope with, leveraging the fact that most of these object and element methods return what’s being manipulated.