javascript エラー「SyntaxError: Unexpected number ‘xxx’. Expected an opening ‘{‘ at the start of a function body.」の解決方法
- 作成日 2022.03.13
- 更新日 2022.10.20
- javascript
- javascript
javascriptで、エラー「SyntaxError: Unexpected number ‘xxx’. Expected an opening ‘{‘ at the start of a function body.」が発生した場合の原因と解決方法を記述してます。
環境
- OS macOS Monterey
- ブラウザ safari 15.5
エラー内容
以下のコードで発生。
const hoge = function() 1
エラーメッセージ
SyntaxError: Unexpected number '1'. Expected an opening '{' at the start of a function body.
画像
原因
「return」文が記述されていないため
解決方法
「return」文を使用する
const hoge = function() {return 1};
-
前の記事
MySQL テーブルデータを倍々にしていく 2022.03.13
-
次の記事
jquery 指定した要素の数を数える 2022.03.13
コメントを書く