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.

script タグ `<script>` 内で 'use strict' の動作メモ

Posted at

script タグ <script> もファイルの先頭で書くのと同様、頭に書けば適用される。

<script>
  'use strict'
  ...
</script>

また、外側の script タグには影響しない。
以下のコードを実行するとエラーが出て、簡単に挙動を確認できます。

<script>
  'use strict'
  foo = 'Set variable test'
</script>
<script>
  bar = 'Set variable test'
</script>

後者の bar の定義は怒られないが 'use strict' を書いた script タグ内の foo は怒られる。
記事を検索したけど見つけられなかったので、ササっと挙動調査したログ残し程度に。

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?