₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,148 members, 8,420,555 topics. Date: Friday, 05 June 2026 at 01:25 AM

Toggle theme

Test Your Javascript Knowledge (pt 3) - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersTest Your Javascript Knowledge (pt 3) (1423 Views)

1 Reply (Go Down)

Test Your Javascript Knowledge (pt 3) by my2cents(op): 4:08pm On Mar 27, 2008
What will be the results of the following alerts, given the code snippet below?

function newClass() {
this.firstName = "Kheme";
lastName = "in Cyprus";
}
var nc = new newClass();
alert(nc.firstName);
alert(nc.lastName);
Re: Test Your Javascript Knowledge (pt 3) by Nobody: 3:32pm On Mar 29, 2008
2 pop up
first 1 says kpeme
second says undefined because the lastname variable you defined in the class has no "this"

so you can't access the variable except from within the class definition


function newClass() {
this.firstName = "Kheme";
lastName = "in Cyprus";
this.seun=lastName; //we are accessing the lastName variable from here
}
var nc = new newClass();
alert(nc.firstName);
alert(nc.seun);
Re: Test Your Javascript Knowledge (pt 3) by my2cents(op): 4:05pm On Mar 29, 2008
Brilliant! cool
Re: Test Your Javascript Knowledge (pt 3) by kheme(m): 7:40pm On Apr 09, 2008
need i say anything?
1 Reply

Test Your Web Programming SkillsTest Your Javascript Knowledge (pt 2)Test Your Javascript Knolwedge.234

Image In File Upload Does Not Show Why? Help PlsWww.exchangeecuurency4naira.com Are Scammers, Worse Than A PlagueIntegrating Biometric Registration On Website