News for hackers. Stuff that matters.
Re:JavaScript Quiz Set by borplk on Saturday January 19, 2013 @08:37AM (#5083334)
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.

Re:JavaScript Quiz Set by dhconnelly on Saturday January 19, 2013 @09:13AM (#5083401)
No, 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)
Re:JavaScript Quiz Set by niggler on Saturday January 19, 2013 @10:44AM (#5083673)
In older versions of C that was the only way to declare variables in a function after the first non-declaration statement.
Re:JavaScript Quiz Set by borplk on Saturday January 19, 2013 @09:38AM (#5083469)
thanks for correction
Re:JavaScript Quiz Set by Serplat on Saturday January 19, 2013 @11:44AM (#5083837)
Original 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_...