dimanche 3 juillet 2016

What is the scope of a variable in a if block in: javascript vs C vs Python?

How is the scope of the a variable in those examples? And how it works in general?

javascript

var a = 0;
if(true){
    var a = 1;
    console.log(a);
}
console.log(a);

C

int a = 0;
if(1){
    int a = 1;
    printf("%i ", a);
}
printf("%i ", a);

Python

a = 0
if True:
    a = 1
    print a
print a

Aucun commentaire:

Enregistrer un commentaire