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 5 years have passed since last update.

JavaScriptのスコープ基本事項

0
Last updated at Posted at 2020-09-29

見本

test.js
class Test {
  constructor() {
   this.test = 'グローバルスコープ';
  }
}

const word1 = 'グローバルスコープ';

function test(){
  let word2 = '関数スコープ';
  if(.....){
    let word3 = 'ブロックスコープ'
  }
}

グローバールスコープ

どこからでもアクセス可能なもの。
また、let、constを省略した場合は関数の中であってもグローバルスコープ。

ローカルスコープ

関数スコープ

関数の中だけ有効となるもの。
ただし、letまたはconstを用いて宣言したものだけが、ブロックスコープ。
let、constを省略した場合は関数の中であってもグローバルスコープ。

ブロックスコープ

{}の中だけで有効なもの。

0
0
0

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?