front-end
front-end3y ago

mzeeshan – 18-54 Dec 25

hello there... Question..... what is the meaning of line 4 , i mean why there is , e .......?
document.body.appendChild(
(function () {
const e = document.createElement("div");
line 4 => return (e.innerHTML = ["Hello", "webpack"].join(" ")), e;
})()
);
document.body.appendChild(
(function () {
const e = document.createElement("div");
line 4 => return (e.innerHTML = ["Hello", "webpack"].join(" ")), e;
})()
);
3 Replies
ScriptyChris
ScriptyChris3y ago
Line 4 uses comma to execute stuff and then return last expression, which is e - so the div https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comma_Operator @mzeeshan It's more readable in this form:
const e = document.createElement("div");
e.innerHTML = ["Hello", "webpack"].join(" ");
return e;
const e = document.createElement("div");
e.innerHTML = ["Hello", "webpack"].join(" ");
return e;
front-end
front-endOP3y ago
thanks a lot
reactibot
reactibot3y ago
This thread hasn’t had any activity in 12 hours, so it’s now locked. Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/1056646116390740100

Did you find this page helpful?