DEV Community

loading...
Cover image for typeerror: object(...) is not a function in Javascript

typeerror: object(...) is not a function in Javascript

joshuabrown0010 profile image joshua-brown0010 ・1 min read

In javascript browsers use javascript engine to execute the javascript code and to show errors in the console, those errors help in improving the performance of the website.
This article discusses the error “typeerror: object(...) is not a function” via example.

Example

<body>
    <a href="javascript:;" id="test">hello</a>
</body>

<script type="text/javascript">
    document.getElementById("test").addEventListener("click", function () {
      test()
    }, false)
    function test() {
      var postTypes = new Array('hello', 'there')   
      (function() { alert('hello there') })()
    }
</script>
Enter fullscreen mode Exit fullscreen mode

Cause

Here the programmer forgot to include semicolon
I know sometimes we don't have to include semicolons in our javascript program. But javascript requires semicolons, the thing is javascript engines insert semicolons for us on the line where it is possible.
Similarly in the above code
var a = new B(args)(stuff)()

Read more

Discussion (0)

pic
Editor guide