Page 269 - Web_Application_v2.0_C12_Fb
P. 269
3. An event is a change in an object’s state. .....................
4. Curly brackets {}, are not mandatory in a JavaScript function. .....................
5. Strings are collections of 64-bit numbers. .....................
6. An event occurs when a user hits a button. .....................
7. The inbuilt function unshift( ) finds a match within a string. .....................
8. JavaScript is an interpreted programming language.
9. The slice() method modifies the original array.
10. The inbuilt function substring( ) returns the position of the first match. .....................
Ans. 1. True 2. False 3. True 4. False 5. False 6. True 7. False 8. True 9. False 10. False
Section B
(Subjective Type Questions)
A. Short answer type questions.
1. Which of the following are valid JavaScript function names?
Add() , function() , average1(), my.name(), NaN(), 2ndobject(), obj_hello(), wellness().
Ans. Add(), average1(), obj_hello(), wellness()
2. Differentiate between replace() and replaceAll() functions with examples.
Ans. replace(): It replaces the first occurrence of a substring with another string.
For example:
var str = "Hello World";
var result = str.replace("World", "JavaScript");
document.write(result);
Output:
Hello JavaScript
replaceAll(): It replaces all occurrences of a specified substring with another string.
For example:
var str = "apple apple apple";
var result = str.replaceAll("apple", "banana");
document.write(result);
Output:
banana banana banana
3. Explain substring( ) and reverse( ) functions with examples.
Ans. substring( ): It extracts the substring using the starting and ending positions as parameters. If the ending
position is left blank, the string will be extracted from beginning to end.
For example: str1 = "Pineapple is very tasty!";
document.write(str1.substring(7,20))
Output: le is very ta
reverse( ): The order of the elements in an array is reversed via the reverse() method. The original array is
overwritten.
JavaScript Part 2 267

