JavaScript TypeError - "X" is not a function
Last Updated :
24 Jul, 2020
Improve
This JavaScript exception is not a function that occurs if someone trying to call a value from a function, but in reality, the value is not a function.
Message:
TypeError: Object doesn't support property or method {x} (Edge) TypeError: "x" is not a function
Error Type:
TypeError
Cause of Error: There is an attempt to call a value from a function, but in reality, the value is not a function. Here the need is to provide a function, but that didn't happen.
Example 1: In this example, the document.getElementByID is used as a function, which is not. So the error has occurred.
<!DOCTYPE html>
<html>
<head>
<title>Type Error</title>
</head>
<body>
<script>
let x = document.getElementByID('GFG');
document.write(x);
</script>
</body>
</html>
Output(In Chrome console):
TypeError: document.getElementByID is not a function
Example 2: In this example, the brackets are used as multiply But they are like calling a function. So the error has occurred.
<!DOCTYPE html>
<html>
<head>
<title>Type Error</title>
</head>
<body>
<script>
const x = 4(4 + 5);
document.write(x);
</script>
</body>
</html>
Output(In Chrome console):
TypeError: 4 is not a function