Variable names (including function names) in Python and JavaScript can belong to different scopes. For example, local variable defined inside function is not accessible from outside of a function.
Python | Javascript |
---|---|
Default variable scope # | |
Inside function, x = 2 Outside function, x = 1
Inside function, x = 2 Outside function, x = 2 To be able to modify the global variable inside a function one
have to use |
Inside function, x = 2 Outside function, x = 2 If one creates variable inside a function in JavaScript, by
default it is a global variable. To declare a local variable,
one have to use command
Inside function, x = 2 Outside function, x = 1
Sum of numbers from 1 to 100 is 5050 And i = 101 We forgot to declare variable |
By default, variable declared inside a function is a local one.