JavaScript TypeError – “X” is not a function

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.



HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
    let x = document.getElementByID('GFG');
    document.write(x);
    </script>
</body>
</html>

chevron_right


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.

HTML

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
<head>
    <title>Type Error</title>
</head>
<body>
    <script>
    const x = 4(4 + 5);
    document.write(x);
    </script>
</body>
</html>

chevron_right


Output(In Chrome console):

TypeError: 4 is not a function

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.