JavaScript document doctype Property Tutorial

In this section, we will learn what the document doctype property is and how to use it in JavaScript.

What is document doctype Property in JavaScript?

The JavaScript document doctype property is used to get the type of HTML document.

For example, if we want to know if the currently loaded document is written using HTML 5 or 4, etc. we could use this property.

The return value of this property is an object called DocumentType object that has a property called “name” by which we can get the name of the doctype.

document doctype Property Syntax:

document.doctype;

document doctype Property Input Value

The doctype property is read-only.

document doctype Property Return Value

The return value of this property is a reference to an object called DocumentType that contains a property called “name”. Using this `name` property, we can get the name of the doctype.

Note: if the doctype is not defined for the current document, the return value of the property will be null.

Example: using document doctype Property in JavaScript

See the Pen using document doctype Property in JavaScript by Omid Dehghan (@odchan1) on CodePen.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies