-1

In this code :

document.getElementById()

Is document an object that has properties and methods?

If yes, is getElementById() a method on this object?

If no, What are document and getElementById considered?

2

2 Answers 2

0

Yes, document is an object.

typeof document; // "object"

And getElementById is a property on that object.

Sign up to request clarification or add additional context in comments.

13 Comments

getElementById is an method of the Document prototype.
Yes, it is inherited via the prototype chain.
!!document.getElementById ==> true
@Kaiido 'getElementById' in document === true The function is still accessible from document, despite not being the direct owner.
@guest271314 document inherits from Document through [currentDocumentType]Document proto. So depending on what are the expectations of OP, it may do an difference.
|
0

In browser, document is a instance of Document. document instanceof Document =>true.

It represents the whole HTML page. And document is a property of window. window.document === document => true.

So it can used as global object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.