I have just learned python
and encountered some problems about the scope of variables, as follows:
the following is not very clear
var a = 3
const f = () => {
a += 4
console.log(a)
}
a() // 7
f() // 7
in js
, you can not only access global variables, but even modify global variables, so what"s the difference between scope mechanism and python
in js
?
in addition, I have learned that js
and python
are static scopes, and the principle should be the same, but the results shown above are very different. Please give me a clear answer. I"m sorry for my lack of knowledge.