0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【関数について】pythonとJavascriptのスコープの違い

Posted at

やろうとしていること

1.グローバルスコープ内で変数を宣言
x
y
z→こいつを関数の中で代入したら、その結果は反映されるのか?
2.関数内でグローバル関数スコープ内で代入

python
x = 100
y = 200
z = 0
def main():
    z = x + y
main() //ここで呼び出し
print(z)

スクリーンショット 2023-02-09 13.39.30.png
→関数内が反映されていないので、0になった

let x = 100;
let y = 200;
let z = 0;

function main(){
	z = x + y;
}
main()

console.log(z)

スクリーンショット 2023-02-09 13.38.10.png
→スコープ内の検索
https://jsfiddle.net/guchon/hxneb6y3/

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?