Page 223 - Web Applications (803) Class 12
P. 223
2. Explain typeof operator in JavaScript with example.
Ans. The typeof operator is a type checking operator in JavaScript that returns the datatype of the operand passed
to it. The argument for the typeof operator can be any variable, function, or object whose type you want to
determine. Example: typeof(“TELEVISION”) will give output as string.
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.
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.
const fruits = ["pear", "pinapple", "guava", "cherry", "olive"]; document.write(fruits.reverse());
Output: olive,cherry,guava,pinapple,pear
4. Explain the unshift method in JavaScript.
Ans. The unshift( ) method inserts new elements at the beginning of an array. The original array is overwritten.
Example:
const col1 = ["blue","green","orange","purple"];
col1.unshift("silver", "golden");
document.write(col1);
Output: silver,golden,blue,green,orange,purple211 Web Scripting—JavaScript
5. How is DOM handled in JavaScript?
Ans. The Document Object Model, or DOM for short, is in charge of determining how distinct objects inside an HTML
document communicate with one another. To create web pages, which contain elements like paragraphs and
links, DOM is necessary. These items can be controlled to do operations like add and delete. A web page also
needs DOM in order to add more features.
B. Long answer type questions.
1. Differentiate between Static websites and Dynamic websites.
Ans.
Static Websites Dynamic Websites
Pages on static websites won't change until they are Pages on dynamic websites have varying contents
manually updated. depending on the visitor.
Take less loading time. Take more loading time.
HTML, JavaScript, and CSS are used to create static CGI, AJAX, PHP, ASP.NET are used to create dynamic
web sites. web sites.
Require less effort and cost in designing. Require more effort and cost in designing.
2. Differentiate between Property and Method through an example.
Ans.
Property Method
Can be value or function. Is a function
Defines the characteristics of an object like size, colour etc. An action performed on objects.
Web Scripting—JavaScript 221

