Jump to content

why is data type function and not object?

Recommended Posts

When i run the code below it outputs:





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>

<p id="demo1"></p>
<p id="demo2"></p>
<p id="demo3"></p>
<p id="demo4"></p>

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;



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 by Allerious
being more clear in my question

Share this post

Link to post
Share on other sites

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: 


Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...