Java-Script
Question 1 |
Consider the JavaScript Code :
var y = "12"; function f() { var y = "6"; alert (this.y); function g() { alert (y); } g(); } f();
If M is the number of alert dialog boxes generated by this JavaScript code and D1, D2, ...., DM represents the content displayed in each of the M dialog boxes, then :
M=3; D1 displays ”12”; D2 displays ”6”; D3 displays ”12”.
| |
M=3; D1 displays ”6”; D2 displays ”12”; D3 displays ”6”. | |
M=2; D1 displays ”6”; D2 displays ”12”. | |
M=2; D1 displays ”12”; D2 displays ”6”.
|
Question 1 Explanation:
The JavaScript this keyword refers to the object it belongs to.
It has different values depending on where it is used:
• In a method, this refers to the owner object.
• Alone, this refers to the global object.
• In a function, this refers to the global object.
• In an event, this refers to the element that received the event.
• Methods like call(), and apply() can refer this to any object.
• There are two alert boxes in the javascript code. So two messages will be displayed.
• First message, alert(this.y) here this.y is global variable whose value is 12. So first message is “12”.
• Second message is alert(y) , here “y” local variable and value is 6 so second message displays value “6”
It has different values depending on where it is used:
• In a method, this refers to the owner object.
• Alone, this refers to the global object.
• In a function, this refers to the global object.
• In an event, this refers to the element that received the event.
• Methods like call(), and apply() can refer this to any object.
• There are two alert boxes in the javascript code. So two messages will be displayed.
• First message, alert(this.y) here this.y is global variable whose value is 12. So first message is “12”.
• Second message is alert(y) , here “y” local variable and value is 6 so second message displays value “6”
Question 2 |
Earlier name of java programming language was:
OAK | |
D | |
Netbean | |
Eclipse |
Question 2 Explanation:
Oak is a discontinued programming language created by James Gosling in 1991, initially for Sun Micro systems' set-top box project. The language later evolved to become Java.
Question 3 |
Which of the following is a platform free language?
Java | |
C | |
Assembly | |
Fortran |
Question 3 Explanation:
Question 4 |
The correct syntax to write “Hi there” in Javascript is
jscript.write (“Hi There”); | |
document.write (“Hi There”); | |
print (“Hi There”); | |
print.jscript (“Hi There”); |
Question 4 Explanation:
JavaScript can "display" data in different ways:
Writing into an HTML element, using innerHTML.
Writing into the HTML output using document.write().
Writing into an alert box, using window.alert().
Writing into the browser console, using console.log().
Writing into an HTML element, using innerHTML.
Writing into the HTML output using document.write().
Writing into an alert box, using window.alert().
Writing into the browser console, using console.log().
There are 4 questions to complete.