What will be the output of the following JavaScript code? [code] function emp(name,salary) { this.name=name; this.salary=salary;

Lượng Tiger

New member
What will be the output of the following JavaScript code?
Code:
function emp(name,salary)
{  
     this.name=name;  
     this.salary=salary;  
     this.changeSalary=changeSalary;  
     function changeSalary(otherSalary)
     {  
         this.salary=otherSalary;  
     }  
}  
e=new emp("Rahul",30000);  
e.changeSalary(45000);  
document.write("e.name+" "+e.salary);
A. Rahul 30000
B. Rahul
C. Rahul 45000
D. 45000
 
Answer: c
Explanation: The above code defines an additional method in JavaScript object. But before defining method, the property should be added in the function with the same name as method.
 

Tìm kiếm

Back
Top