Bio Hazard Bio Hazard - 2 months ago 14
Javascript Question

JavaScript weird assignment code

I found this line of code in a project and I couldn't under

return d.isPointInside(a, b) ? (console.log("runned"), c = !0, !1) : void 0


And I couldn't understand the part:

(console.log("runned"), c = !0, !1)


The word "runned" should be displayed in the browser's console, But need some help to understand the rest.

Answer

Just some type juggeling

!0 === true
!1 === false
void 0 === undefined

The result with some longer words:

(console.log("runned"), c = true, false);

The complete return statement reads as following, without use of the Comma Operator:

if (d.isPointInside(a, b)) {
    console.log("runned");
    c = true;
    return false;
} else {
    return undefined;
}
Comments