初級 › TypeError: x is not a function の原因と直し方 › パターン1
TypeError: x is not a function の原因と直し方
関数ではない値を関数として呼び出そうとしたときに出るエラーです。
1 const total = 5; 2 function getTotal() { return total; } 3 console.log(________()); ^
main.js:3
console.log(total());
^
TypeError: total is not a function
空欄を埋めて実行を通す
totalは数値であって関数ではありません。呼び出した結果を得たい場合は、値を返す関数(ここではgetTotal)を呼びます。
次の問題