5 ms·
Second example, "function scope" "Based on knowledge of several other languages (such as Java or C), this would certainly be true. However, Javascript doesn't
by borplk 14y ago
Second example, "function scope"
"Based on knowledge of several other languages (such as Java or C), this would certainly be true. However, Javascript doesn't change scope when entering if statements, loops, or anything like that, really."
Dude what the hell?
In Java and C, 'if' blocks don't have their own isolated scope either. The equivalent Java or C code would also work perfectly fine.
- dhconnelly 14y agoNo, you're incorrect, C and Java do have block scope. It would have taken like 5 seconds to verify that. In C: #include <stdio.h> int main() { if (1) { int a = 5; } printf("%d\n", a); return 0; } ==> test.c:6: error: ‘a’ undeclared (first use in this function)
- Serplat 14y agoOriginal author of that quiz here. As dhconnelly pointed out, Java and C definitely do have their own isolated scope for 'if' blocks. More information: http://en.wikipedia.org/wiki/Scope_(computer_science)#Scope_within_a_function http://en.wikipedia.org/wiki/Scope_(computer_science)#Scope_...