Weiter zur NavigationWeiter zum Inhalt
Anzeige
Anzeige
Anzeige

Javascript Weird Parts -

const obj = { show }; obj.show(); // obj

function getObject() { return { value: 42 } } console.log(getObject()); // undefined javascript weird parts

Put { on the same line as return . 6. this – The Shape-Shifter In most languages, this is predictable. In JavaScript, it depends on how you call the function. const obj = { show }; obj

These quirks are frustrating until you understand why they exist. Once you do, you stop fighting the language and start leveraging it. In JavaScript, it depends on how you call the function

const arr = [1, 2, 3]; const obj = { a: 1 }; console.log(arr + arr); // "1,2,31,2,3" (string) console.log(arr + obj); // "1,2,3[object Object]"

Both get converted to strings and concatenated. Not an error. Not useful. Just... weird. JavaScript’s weird parts aren’t bugs—they’re historical artifacts. Brendan Eich built this language in 10 days in 1995. It had to be flexible, forgiving, and fast.

javascript weird parts
Anzeige