How to get the title of HTML page with JavaScript?

How to get the title of HTML page with JavaScript?

How can I get the title of an HTML page with JavaScript?

Solutions/Answers:

Solution 1:

Use document.title:

console.log(document.title)
<title>Title test</title>

MDN Web Docs

Solution 2:

Put in the URL bar and then click enter:

javascript:alert(document.title);

You can select and copy the text from the alert depending on the website and the web browser you are using.

Solution 3:

Can use getElementsByTagName

var x = document.getElementsByTagName("title")[0];
alert(x.innerHTML)

Related:  jQuery .each() function with ES6 arrow functions [duplicate]