javascript エラー「Uncaught SyntaxError: Unexpected strict mode reserved word」の解決方法
- 作成日 2022.03.09
- 更新日 2022.10.17
- javascript
- javascript

javascriptで、エラー「Uncaught SyntaxError: Unexpected strict mode reserved word」が発生した場合の原因と解決方法を記述してます。
環境
- OS windows11 pro 64bit
- Apache 2.4.43
- ブラウザ chrome 106.0.5249.103
エラー内容
以下のコードで発生。
'use strict'
const package = [0, 1, 2]
エラーメッセージ
※以下のエラーは「use strict」の厳格モードのみで発生します。
Uncaught SyntaxError: Unexpected strict mode reserved word
画像

firefox(バージョン105)では、以下のエラーとなります。
Uncaught SyntaxError: package is a reserved identifier
画像

原因
厳格モード(use strict)では、予約語である「package」はエラーとなるため
解決方法
厳格モード(use strict)を記述しないか、他の名称に変更する
'use strict'
const package_ = [0, 1, 2]
-
前の記事
C# mysqlに接続してテーブルを作成する 2022.03.09
-
次の記事
Linux ホスト名を確認する 2022.03.09
コメントを書く