- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
if (!a) {
a = 1;
} else {
a = 2;
}
var a = undefined;
console.log(a); //undefined
if (!a) {
a = 1;
} else {
a = 2;
}
var a ;
console.log(a); //1
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−1
if (!a) {
a = 1;
} else {
a = 2;
}
var a = undefined;
console.log(a); //undefined
if (!a) {
a = 1;
} else {
a = 2;
}
var a ;
console.log(a); //1
Именно поэтому я за let.
это должно было быть 2 разных примера...
Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.
http://ideone.com/F4ERQm
https://ideone.com/nYXQki
Что это за синтаксис такой - объявлять блок кода в фигурных скобках после блока if-else?
https://code.woboq.org/userspace/glibc/stdlib/qsort.c.html
https://isocpp.org/wiki/faq/inline-functions#inline-vs-macros
https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-if
https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-multi-stmts
https://isocpp.org/wiki/faq/misc-technical-issues#macros-with-token-pasting
*****
Here’s a naive solution:
This will cause big problems if someone uses that macro in an if statement:
The problem is that the else baz nests with the wrong if: the compiler sees this:
Obviously that’s a bug.
Красивый смайлик в последней строчке?
http://ideone.com/EDMStp
Это же форт, будет выглядеть как захочешь.