Обратный
звонок
Время работы:
пн - пт: 09:00 — 20:00 |
сб - вс: 09:00 — 18:00
0
Сравнение
0
КАТАЛОГ ТОВАРОВ

Автоматические насосные станции

Горизонтальные центробежные насосы

Вертикальные центробежные насосы

Установки повышения давления и пожаротушения

0 Сумма:

Weird Parts |top| - Js The

const bound = showThis.bind("hello"); bound(); // String {"hello"}

If you’ve spent more than five minutes writing JavaScript, you’ve probably had a moment where you stared at your screen and whispered, “...why?” js the weird parts

So next time you see [] + [] returning "" , don’t cry. Laugh. Then fix it. And remember: you’re not alone. What’s the weirdest JavaScript bug you’ve ever encountered? Hit reply or drop a comment—I’d love to compare war stories. const bound = showThis

console.log([] + []); // "" (empty string) console.log([] + {}); // "[object Object]" console.log({} + []); // 0 (wait, WHAT?) The last one is a parsing quirk. In some engines, {} at the start of a line is treated as an empty block, not an object. So {} + [] becomes + [] which coerces to 0. Never, ever trust == . It’s like asking a toddler if two things are the same. And remember: you’re not alone

console.log(isNaN(NaN)); // true // But wait... console.log(isNaN("hello")); // true (because "hello" can't be a number) That’s why ES6 gave us Number.isNaN() which actually behaves. In many languages, if you forget to declare a variable, you get an error. In JavaScript (non-strict mode), you get a present :

function showThis() { console.log(this); } showThis(); // window (or undefined in strict mode)

You are not alone. JavaScript is the quirky, misunderstood genius of the programming world. It was built in 10 days, it drives the modern web, and it has a list of "features" that look more like bugs.