-3
function myFunction() {

   alert(window[title]);

}
myFunction();

I'm expecting to this see the html the title page.

user660943
  • 85
  • 2
  • 6
  • 2
    `ReferenceError: title is not defined`. [Learn how to debug JavaScript](http://www.creativebloq.com/javascript/javascript-debugging-beginners-3122820) – Felix Kling Jun 25 '14 at 22:22

2 Answers2

5

First off, title doesn't belong to window. It belongs to document.

Secondly, you've mixed dot notation and array indexer notation, you either need:

alert(document['title']);

Or:

alert(document.title);

Unless, of course, you have a variable called title that holds the string 'title', in which case it would look something like:

var title = 'title';
alert(document[title]);
Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
5
function myFunction() {

   alert(document.title);

}

First off, window[title] will make javascript look for the undeclared variable title; you probably meant window['title']. Second you want document.title

megawac
  • 10,953
  • 5
  • 40
  • 61