Allerious Posted April 25, 2019 Share Posted April 25, 2019 (edited) When i run the code below it outputs: object function function function I don't understand why 'Array' is being output as 'function'. Is it not an object? 'Array' is the object and 'Array.isArray' is the method/function of that object. <!DOCTYPE html> <html> <body> <p id="demo1"></p> <p id="demo2"></p> <p id="demo3"></p> <p id="demo4"></p> <script> var myObj = { name: "bob", age: 50, nameAge : function() { return this.name + " " + this.age; } } var x = document.getElementById("demo1"); x.innerHTML = typeof myObj; var x = document.getElementById("demo2"); x.innerHTML = typeof myObj.nameAge; var x = document.getElementById("demo3"); x.innerHTML = typeof Array; var x = document.getElementById("demo4"); x.innerHTML = typeof Array.isArray; </script> </body> </html> Maybe 'isArray' is a function nested within the 'Array' function? If this is the case what would the syntax be for creating this? For example how would i change the following so myFun.withinFun() outputs "test" function myFun(){ function withinFun(){return "test"} } Edited April 25, 2019 by Allerious being more clear in my question Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2019 Share Posted April 25, 2019 Array is a function that returns an array object. If that makes sense. In Javascript, functions, arrays, and objects are all very closely related. The syntax is even interchangeable: window["alert"]("what"); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now