javascript エラー「Uncaught TypeError: Right-hand side of ‘instanceof’ is not an object」の解決方法
- 2022.06.17
- javascript
- javascript

javascriptで、エラー「Uncaught TypeError: Right-hand side of ‘instanceof’ is not an object」が発生した場合の原因と解決方法を記述してます。
環境
- OS windows11 pro 64bit
- Apache 2.4.43
- ブラウザ chrome 102.0.5005.115
エラー内容
以下のコードで発生。
"hoge" instanceof "string"
エラーメッセージ
Uncaught TypeError: Right-hand side of 'instanceof' is not an object
画像

firefox(バージョン97)では、以下のエラーとなります。
Uncaught TypeError: invalid 'instanceof' operand "string"
画像

safari(15.0)では、以下のエラーとなります。
TypeError: Right hand side of instanceof is not an object
画像

原因
右側に指定する値は、prototypeプロパティをもつ必要があるため
解決方法
型を判定する場合は、「typeof」を使用する
typeof "hoge" == "string"
実行結果

-
前の記事
Oracle Database 文字列を結合する 2022.06.16
-
次の記事
python enumerateで指定した開始番号からスタートする 2022.06.17
コメントを書く