3 ms·
Javascript requires explicit variable declaration if you're bringing it to a new scope, though. Which is to say: var s = "Geeksforgeeks"; function f_gl
by kevinmgranger 5y ago
Javascript requires explicit variable declaration if you're bringing it to a new scope, though. Which is to say:
var s = "Geeksforgeeks";
function f_global() {
s = "Me too";
}
// is different from
function f_local() {
var s = "Me too";
}
- sgc 5y agoI like that better (and I realize I might be alone!). But I don't like that you can declare a global variable in a local function by omitting the var. It's a similar needless ambiguity and frankly much more prone to errors than the python local variable initialization. At least there is strict mode.