Page 271 - Web_Application_v2.0_C12_Fb
P. 271
}
document.getElementById("demo2").innerHTML = x +20
myFunction();
</SCRIPT>
</BODY>
</HTML>
Ans. The output of the given code will be:
JavaScript Functions
45
190
8. Consider the following JavaScript code and predict the output: [CBSE Handbook]
<!DOCTYPE HTML>
<HTML>
<BODY>
<H2>JavaScript Functions</H2>
<P ID="demo1"></P>
<P ID="demo2"></P>
<SCRIPT>
var x=55
var y=15
function myFunction()
{ var x=100
var y=40
x++
return x+y }
document.getElementById("demo2").innerHTML = x+y
document.getElementById("demo1").innerHTML=myFunction()
</SCRIPT>
</BODY>
</HTML>
Ans. JavaScript Functions
141
70
B. Long answer type questions.
1. Explain the following functions with examples:
i. substring()
ii. concat()
iii. charAt()
iv. trim()
Ans. i. substring() extracts characters between two indices.
For example:
var str = "JavaScript";
var result = str.substring(4, 10);
document.write(result);
Output:
Script
JavaScript Part 2 269

