[go: up one dir, main page]

100% found this document useful (1 vote)
2K views72 pages

3 Advanced Javascript

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 72

Advanced JavaScript

I Chapter at a Glance

Types of Scripting: •
CUont Sid" Scripting 4r Server SidIoSc'ripting.Differenre
between Client Side and Serv!'>rSide Stripting

Switch C••se : - looping statement, -


It is .1 built inl,llulti_way decisioa statement. For ... loopsynl". and "'''mp1'', Whil" ... loop syntax
gynt""" of. switch cas" wilh example and example, do .... while loop syntax and example,
Break •••.•
d rontinue stat;;m~l'ils"

[ 3.30bje<\s in
)avaStript

T
1

DOM (l)ocQment Qbject Modell: •
o.,iiniIion, Method and Properly of OOM obit"'t
Window Objecl : •
Definition, Method and I'toperty
• of Window object,
:P«)perly Jike head, titl", URL, bod)l, bllg, Propert}' like n~=, lot,ti'iol'l, document, status, closed,
Methedslike writeO, writoln(), g"tElemenlByldO Melhod like ilIlerl(j,confirm{i. promptO, opent), dQ$<>(j,
:wIth e~ample;;. blur{), tocus{), pdl'lt(), setTirneQulO with e~mllpl~

Event 1Il".millg "lid ""I.imilaIion, Event handler like onblu" ontocus,


Qllcit<>n!:e.•onselect, onsubmit, onreset, onload, onunlead

String object 1- Math object,· Date object' • Numbuobi"d, • Amy oblecl :.


Property: ' length. Method.: ' ilh;(), ell Metb,,;!: • gell)~yO, Property: ' Prol'ert}" - index,
Method; - cl,arAi(), ceiIO,floorO, mm<(), g"ID.I"O, gelHollrs(), J\UN_VAWE. \imsth
indcxOf(), m·"O.powO, gelMonthO, l'iQwO. MAx',VALUE MeUlo<l: - cOllcal!).
1~;~llndexOfO, raml"mO, "'1ft!} g<!tTim~(),;;;tD a (~O, Meth<ld: ·isln1eg"rO, C<lpyW!thin(), fi11dO,
substrf), .ubslring(), setfu IlYt,arO, par;>&FI<lat\), forEachO, i,sAmlY(),
trimO, ioLQwerCMe\), seIH"uN(j, pdrselnl(J, pop{), pushO,
to UpperC"",,'() s.,tTim>'] i.FixedO rev ••fSL'O, $OrtO
TPS Information Technology (Science) 3-2 Advanced JavaScript

3.1 Introduction
1~ is an interpreted scripting language.
Ans. : JavaScript
2. . ; is a set of instructions used to produce various kinds of outputs.
Ans. : Program
3. The programs in javaScript language are called .
Ans. : Scripts . ,
4'. .. is an object oriented scripting language and supports event based
programming facility.
Ans. : JavaScript
5. .. is platform independent scripting language.
Ans.: JavaScript
6. .. is knows as Universal client side scripting language.
Ans.: JavaScript
7. In ~ scripting the script resides on the client computer.
Ans. : Client side
8. In scripting the script resides on web server.
Ans. : Server side
9. .. scripting does not need any server interaction.
Ans. : Client side
10. .. ~ scripting communicates to the server.
Ans. : Server side
11. .. scripts 'are used for validation purpose.
Ans. : Client side.
12. .. scripts requires web browser as on 'interface.
Ans. : Client side
13. .. , scripts requires web server software to execute.
Ans. : Server side
14. .. is a JavaScript based open source frontend web framework
developed for single page application.
Ans. : Angular JS
15. .. is JavaScript based framework for building interactive user
interface.
Ans.: Vue Js.
Tf'Sfnformation Technology (Science) 3-3 Advanced JavaScript

16. . consists of JavaScript libraries for building VI for single page


application and mobile application ..
Ans. : React

3.2 Switch case and Looping Structures


17. JavaScript has a built-inmultiway decision statement known as .: .
Ans. : Switch
18. . : : refers to the execution of statement or a group of statements of
code for a fixed number of times.
Ans. : Iteration
19. loop combines initialization, condition and. loop iteration in
single statement.
Ans.: For
2~. . ; means increment or decrement value of a running variable.
Ans. : Iteration
21. .. statement is used to jump out of loop.
Ans.: Break
22. When it is necessary to skip statement block and take the control at the beginning
for next iteration statement is used. .
Ans. : Continue

3.30bjeds in JavaScript
23. The keyword is used to create new object in JavaScript.
Ans. : new
24. An :..•........ can group data together with functions needed to manipulate
it.
Ans.: Object
25. All tangible things are known as .
Ans. : Objects
26. DaM stands for : .
Ans. : Document Object Model
27. The way in which HTML document content IS accessed and modified is called as

Ans. : Document Object Model


28. property of DaM object returns the <head> element of the
document.
Ans.:Head
TPS Information Technology (Science) 3-4 Advanced JavaScript

29. . ; property of DOM object sets or returns title of the document.


Ans.: Title
30. .. : property of DOM object returns URL of the HTMLdocument.
Arts.: URL
31. .. method of DOM object writes HTML expressions or Iavafcript
code to a document.
Ans, : writeO
32. method of DOM object adds a newline character after each
statement.·
Ans. : writelnO
33. Using 'method id properly is used to find an element.
Ans. : getElementByIdO
34. The : property is useful for getting html element and changing its
content.
Ans, : innerHTML
35. .. object is parent of all other objects.
Ans. : window
36. .. object represents an open window in a browser.
Ans. : window
37. property of window object sets or returns the name of the
window.
Ans. : Name
38. .. property of window object returns the location object for the
window.
Ans. : location
39. .. ;.. property of window object returns the document object for the
window.
Ans.; document
40. .. property of window object sets or returns the fact in the status
bar of a window.
Ans. : status
41. . : property of window object returns a Boolean valve indicating
whether a window has been dosed or not.
Ans. : closed
42. .. ; method of window object display the alert box containing
message with OK button.
Ans. : alert 0
TPS InformationTechnology'(Science) 3-5 Advanced JavaScript

43. . method of window object displays the confirm dialog box


containing message with ok and cancel button.
Ans. : confirmO
44. .. method of window object displays a dialog box to get input from the
user.
Ans. : promptO
45~ method of window object opens the new window.
Ans.: openO
46. .. , method of window object closes the current window.
Ans. : c1oseO ,
47. ..: method of window object removes focus from the current window.
Ans, : blurO
48~ method of window object sets focus to the current window.
Ans. : focusO
49. ......•..................method of window object prints the content of current window.
Ans. : printO
50. ' ; method of window object calls a function or evaluates an expression
after a specified number of milliseconds.
Ans. : setTimeoutO

3.4 JavaScript Events


51. .. are the actions done by users or an application that occurs on the
webpage ..
Ans.: Events
52. event handler occurs when user leaves field or looses focus of an
element.
Ans. : onblur
53. . ..: event handler occurs when an element gets focus.
Ans. : onfocus
54. ..., event handler occurs when user changes content of an element or selects
drop down list ..
Ans.: onchange
55. .. event handler occurs when user selects same text of an element.
Ans. : onselect
56. .. : event handler occurs when user clicks submit button.
Ans. : onsubmit
57. .. : event handler occurs-when user clicks reset button.
Ans. : onreset
TPS Information Technology (Science) 3-6 Advanced·JavaScript

58. ; event handler occurs when page/image has been loaded.


Ans. : onload
59. event handler occurs when document page has been unloaded or
closes.
Ans, : onunload

3.5 .]avaScl'ipt built-in Objects"


60. .. object is used to store or manipulate text.
An~. : Strin:g
61. .. ; property of string object returns number of characters in a string.
Ans. : Length
62. method of string object returns the character at the specified
position.
Ans. : charAtO
63. '. . : method of string object returns the index: of the first occurance
of specifiedcharacterin given string.
Ans. : indexOf()
64. method of string object returns the index of last occurance of
specified character in given string. ~
Ans. : lastIndexOfO
65. .. "method of string object removes whitespace from both sides of a
string.
Ans. :trimO
66. .. , method of string object converts a string to lower case.
Ans. : toLowerCaseO "
67. .. method of string object convert a string to upper case.
Ans. : toUpperCaseO
68. The built in : object includes mathematical constants and functions.
Ans.:math
69. .. method. of math object returns the absolute value of a number.
Ans. :absO
70. .. method of Math object returns the cube root ofa number.
Ans.: cbrtO
71. method of math object returns the next integer grater than or
equal to a given number.
Ans. :ceilO
72. .. method of math object "returns the next integer less than or equal to a
given number.
Ans, : floorO
TPS Information Technology (Science) 3-7 Advanced javaScript
,
73. . ; ; method Ofmath object returns the highest valued number in a list
of numbers.
Ans. :maxO
74. . method of math object returns the lowest valued number in a list of
numbers.
Ans.: minO
75. . method of math object returns the base to the exponent power.
Ans. :powO
76. . method of math object returns a random number between 0
and l.
Ans.: randomO
77. ...; method of math object returns the square root of a number.
Ans.: sqrtO
78. . objectis used to create date and time values.
Ans.:date
79. .. method of date object returns the day of the month.
Ans. : getDateO
80. .. method of date object returns the day of the week.
Ans. : getDayO
81. .. method of date object returns the year.
Ans.: getFullYearO
82. .. ; method of date object returns the hour.
Ans. : getHoursO
83. .. method of date object returns the minutes.
Ans. : getMinutesO
84. .. ~ method of date object returns the month.
Ans. : getMonthO
85. . ~ method of date object-returns the seconds.
Ans. : getSeconds()
86. , method of date object sets the day of the month.
Ans. : setDateO
87... method of date object sets the full year.
Ails. : setFullYearO
88. .. method sets the hours of a date object.
Ans. : setlfoursf)
89. : method sets the"minutes of a date object.
Arts. : setMinutesO
TPS Information Technology (Science) 3-8 Advanced JavaScript

90. . method sets the month of a date object.


Ans, :setMonthO
91. . method sets the seconds of a date object.
Ans. : setSecondsO
92. : method sets a date to a specified number of milliseconds
after/before [an I, 1970.
Ans, : set'I'imef)
93. . object helps us to work with number.
Ans, : Number
94; property of Number object returns the largest minimum value.
Ans. :MIN_VALUE
95. . :......... property of number object returns the largest maximum
value.
Ans. : MAX_ VALUE
·96. . property of Number object represents not a number value.
Ans.:NaN
97. . method of number object determines whether the given value is
a Integer.
Ans. : isIntegetO
98. method of number object converts the given string into a
floating point number.
Ans. : parseFloatO
99. method of Number object converts the given string into a
integer number.
Ans. : parseInt()
100. . ; : method of number object returns the string that represents a
umber with exact digits after a decimal point.
Ans.: isFixedO
101. An is an object that can store a collection of items.
Ans. : Array
102. An .......•............................. is a special variable which can hold more than one value at
a time.
Ans. : Array
103. The index of the first element of an array is .
Arts. : Zero
104. .........•.........................'is referred to access and set the items in an array.
Ans, : IndexNumber
105. ..........•........................ property of Array object represents the zero based index of the
match in the string.
Ans. : Index

,.
TPS Information Technology (Science) 3-9 Advanced JavaScript

106. . property of Array object reflect number of elements in array.


Ans. : length
107. . method of array object joins two or more arrays and returns a
copy of the joined arrays.
Ans. : concatO
108. . method of Array object copies array elements within the
array, to and from specified position ..
Ans. : copyWithinO
109. . method of array object returns the value of the first element in an
array that satisfies a test in testing.
Ans. : findl)
110. . method of Array object calls a function for each array element.'
Ans.: forEachO
111... method of Array object search the array for an element and
returns its position. .'
Ans. : iridexOfO
112. . method of array object checks whether an object is an array.
Ans. : isArrayO
113. .. method of array object removes the last element of an array
and returns that element.
Ans.: popO
114. ~ method of array objectadds new elements to the end of an array.
Ans. : pushO
115 method of arrC;lyobject reverses the order of the elements in an
array.
Ans. : reverse()
116... method of array object sorts the elements of an array.
Ans. : sortO

3.1 Introduction
1. JavaScript is an involved scripting language.
Ans.: False
2. An interpreted language is a. type of programming. language that executes its
instructions directly without compiling machine language.
Ans. : True
TPS Information Technology (Science) 3~10 Advanced JavaScript

3. Program is a set of instructions used to produce various kinds of outputs.


Ans. : True
4. JavaScript was created to destroy web pages.
Ans.: False
5. There is no need of special software to run JavaScript program.
Ans. : True
6. Java script is an object oriented scripting language.
Ans.:True
7. JavaScript is not case sensitive language ."
Ans.: False
8. JavaScripthelps the browser to perform input validation.
Ans.: True
9. JavaScript cannot handle date and time.
Ans.: False
10. JavaScript has the ability to create new functions within scripts.
Ans. : True
11-. Functions are declared in JavaScript using var keyword.
Ans.: False
12.· "Software that can run on any hardware platform is called as platform independent
" software." "
Ans, : True
13. [avafcript is platform independent scripting language.
Ans. : True
14. There are two types of scripting.
Ans. : True"
15. :rn: client side scripting, the script resides on client computer and that can run on the
client.
Ans. : True
16. Client side scripts are placed inside HTML document.
Ans. : True
17. In Server side scripting the scripts resides on web server.
Ans.:True
18. Server side scripting is used at the front end.
Ans.: False
19. Clientside scripting is used at the front end.
Ans. : True
20. When a server side script is processed it communications to the client. "
Ans.: False
TPS Information Technology (Science) 3-11 Advanced JavaScript

21. Client side scripting does not need any server interaction.
Ans. ::J'rue
22. PHP, ASP.net etc are server side scripting languages.
Ans. : True
23. Client side scripts are generally used for validation purpose.
Ans.: True

3.2 Switch case and Looping Structures


24. JavaScript has a built-in multiway decision statement known has switch.
Ans, : True
25. There should not be duplicity between the cases.
Ans, : True
26. The value for the case must be similar data type as the variable in switch.
Ans. : True
27. Iteration refers to the execution of statements of code for a fixed number of times till
the condition is satisfied.
Ans, :.True·
28. For loop combines initializing, condition and loop iteration in single statement.
Ans. : True
29. Loop will execute statement in statements block will the condition is false.
Ans.: False
30. Iteration means increment or decrement value of a running variable.
Ans. : True
31. While loop executes statements as long as the condition is false.
Ans.: False
32. Break statement is used to jump out of loop.
Ans.:.True
33. Continue sta~ement is used to make early exit from a loop.
Ans.: False
34. Continue statement is used to skip statement block and take the control at the
beginning for next iteration.
Ans.:True

3.3· Objects in JavaScript


35. [avabcript is an object based scripting language.
Ans. : True
36. A.JavaScript object is an:entity having properties and objects.
Ans. : True
TPS Information Technology (Science) 3-12 Advanced JavaScript

37; Properties and methods of object are accessed with "," Operator.
Ans. : True
38. JavaScript supports 4 types of objects.
Ans.: False
39. JavaScript gives facility to create user defined objects.
Ans.: True
40. The new keyword is used to create new object in JavaScript.
Ans.: True
41. DOM stands for Document Original Model. .
Ans.: False
42. The way in which HTML document content is accessed and modified is ~called as
DOM.
Ans, : True
43. Head property of DOM object returns the <head> element of the document:
Ans.: True
44. Title property is DOM object returns the name of the document.
Ans.: False
45. URL property ofDOM object returns full URL of the HTML document.
Ans. : True
46. Body property of,DOM object returns <body> elements respectively.
Ans. : True
47. writet) method of DOM object write Java script code to a document.
Ans. : True
48. writelnO method is same as write ( ) method of DOM object.
Ans.: False
49. writelnt) method of DOM object adds a new line character after each statement.
Ans. : True
50. The outerHTML property is used to change any HTML element.
Ans.: False
51. window object is parent object of all other objects-.
Ans.: True
52. An object of window is created automatically by the browser.
Ans.: True
53. name property of window object sets or returns the name of a window.
Ans. : True
54. location property of window object returns a' Boolean value indicating whether a
window has been dosed or not.
Ans. : False
TPS Information Technology (Science) 3-13 Advanced JavaScript

55. document property of window object returns the document object for the window.
Ans. : True
56. . status property of window object sets the name of a window.
Ans.: False
57. alertrjmethod of window object displays the alert box containing message with ok
button.
Ans, :True
58. promptt) method of window object displays a dialog box to set output for the user.
Ans.: False
59. confirmf) method of window object displays the confirm dialog box containing
message with ok and cancel button:
Ans. : True
60. open( ) method of window object removes the focus from the current window.
Ans.: False
61. closet) method of window object closes the current window.
Ans.r True
62. blurt) method of window object removes focus from the current window.
Ans. : True
63. focusi) method of window object removes focus from the current window.
Ans.: False·
64. printO method of window object prints the content of current window .
. Ans. : True
65. setTimeoutO method of window. object calls a function after a specified number of
milliseconds.
Ans. : True

3.4 JavaScript Events


66. Events are the actions done by the user or an application that occurs on the web
page.
Ans.:True
67. onKeyPress, onKeyDown are keyboard events.
Ans. : True
68. onClick, onMouseUp ate mouse events.
Ans. : True
69. onblur event handler occurs when an element gets' focus.
Ans. : False
70. onfocus event handler occurs which an element gets focus.
Ans.: Trite
TPS Information Technology (Science) 3-14 Advanced JavaScript

71. onchangeeventhandler occurs when user changes content of an element.


Ans. : True
72. onselect event handler occurs when page image has been loaded.
Ans.: False'
73. onsubmit event handler occurs when user clicks submit button.
Ans. : True
74. onreset event handler occurs when user clicks reset button.
Ans.:True
75.' onload event.handler occurs when document/page has be loaded.
Ans. : True
76. onunload event handler occurs when user clicks on submit button.
Ans.: False

3.5 JavaScript built-in Objects


77. String is used to store zero or more character of text Within,single or double quotes.
Ans. : True
78; String objectis used to store and manipulate numbers.
Ans.: False
79. length property returns the number of characters in a string.
Ans.:True
80. charAtO method of string objectreturns the character at the specified position.
Ans.: True
81.indexOfO method of string object returns the index of the middle occurrence of the
specified character in the given string.
Ans. : False
82. lastIndexOfO method of string object.returns the index of the last occurrence of
specified character in given string.
Ans. : True
83. substrt) method of string objectreturns the characters you specified.
Ans.: True
84. trimf) method of string objects adds the white spaces from both sides of a string.
Ans.: False
85. toLowerCaseO method of string object converts a string to capitals.
Ans.: False
86. tol.Ipperf.asef) method of string object converts the string to upper case.
Ans. : True
87. The Math object includes mathematical constants and functions.
Ans. r True
TPS Information Technology (Science) 3-15 Advanced JavaScript

88. There is no need to create a Math object before using it.


Ans. : True
89. abst) method of math object returns square root of a number.
Ans, : False
90. cbrtt) method of math object cube root.of a number.
Ans.: True
91. ceilt) method of math object returns the next inter greater than or equal to a given
number.'
Ans. :True
92. floort) method of math object returns the next integer less than or equal to a given
number.
Ans. : True
93. maxOmethod of math object returns the smallest valued number of a list of
numbers.
Ans.: False
94. miru) method of math object returns the power of the number.
Ans.: False
95. powO method of math object returns the base to the exponent power.
Ans.: True
96. randamO method of math object returns a random number between 0 and one.
Ans.:True
97.· sqrtt) method of math object returns the square root of anumber.
Ans. : True
98. The time object is used to create date and time values.
Ans.: False
99. Dat~ object is created using new keyword.
Ans. : True
100. getDateO method of date object returns the day of month.
Ans.:True
101. getDayO method of date object returns the day of the month.
Ans.: False
102.. getFullYearO method of date object returns the year.
Ans. : True
103. getHours() method of Date object returns the month.
Ans.: False
104. getMinutesO method of Date object returns minutes.
Ans, : True
TPS Information Technology (Science) 3-16 Advanced JavaScript

105. getMonthO method of Date object returns month name.


Ans.: False
106. getSecondsO method of Date object returns seconds.
Ans. : True
107. getTimeO method of Date object returns date.
Ans.: False
108. nowt) method of Date object returns the number of a milliseconds.
Ans. : True
109. setDate() method of Date object set day of the month of a date object.
Ans. : True
110. setFullYearO method of Date object sets year.
Ans. : True
111. setH ours/) method of Date object set the seconds.
Ans.: False.
112: setMinutesO method of Date objects sets minutes.
Ans. : True
113. setMonthO method of Date object sets month.
Ans. : True
114. setSecondsO method of Date object sets hours.
Ans.: False
115. sefTimet) method of ~ate object sets a date to a specified number of milliseconds.
Ans.: True
116. .Number object helps us to work with numbers.
Ans. : True
117. MIN_ VALUE property of number object returns the largest minimum value.
Ans.: True
118. MAX_ VALUE property of number objects returns the largest minimum value.
Ans.: False
119. NaN property of number of object returns Not a Number value.
Ans.: True
120. islntegert) method of number of object determine whether the given value is a
character.
Ans.: False
121. parseFloatO method of number object converts the given string into a-floating point
number. . ,
Ans. : True
122. parselntt) method of number object converts the given string into a integer number.
Ans. : True
TPS Information Technology (Science) 3~17 Advanced JavaScript

123. isFixedO method of number object returns the string that represents a number with
exact digits after a decimal point. .
Ans.: True
124. An array is an object that can store a collection of items.
Ans, : True
125. Arrays are used to store single value in singlevariable.
Ails.: False
126. Items of array can be accessed by referring to its index number.
Ails. .True
127. Indexof first element of an array is one.
Ans.: False
128. marks[O] is the first element ofthe array.
Ans. : True
129. Index property of Array object represents two based index of the matching the
string.
Ans.: False
130. Length property of Array object reflects number of elements in array.
Ans. : True
131. concatO method of Array object joins two or more arrays and returns a copy of
joined array.
Ans.: True
132. copyWithinO method of Array object adds array elements within the array to and
from a specified positions,
Ans.: False
133. find 0 method of Array object returns the value of the first element in art array that
satisfies a test in testing. .
Ans, : True
134. forEachO method of Array object search-the array and returns it's position.
Ans.: False
135. indexOfO method. of Array object search the array for an element and returns its
position. . .
Ans. : True
136.' isArray() method of Array object removes element from array.
Ans.: False
137. popljmethod of Array objects removes the last element of an array and returns that
element.
Ans.: True
138. pusht) method of Array object add new elements to the end of an array and returns
the new length .
. Ans.:True
TPS Information Technology (Science) 3-18 Advanced JavaScript

139. reverser) method of Array object returns the elements in an array.


Ans. : False
140. sortt) method of Array object sorts the elements of an array.
Ans. : True .

1. . is an interpreted scripting language.


(a) PHP (b) C++ (c) HTML (d) JavaScript
Ans.: (d)
2. . : is a set of instructions used to produce various kinds of outputs.
(a) Design (b) Software (c) Program (d) Hardware
Ans.: (c)
3. The programs in JavaScript language are called .
(a) Website (b) Scripts (c) Web server (d) Software
Ans. : (b)
4. .. ; is an object oriented scripting language and supports event based
programming facility.
(a) JavaScript (b) C++ (c) Excel (d) Word
Ans. : (a)
5. .. is platform independent scripting language.
(a) MSWord (b) JavaScript (c) PHP (d) C++
Ans. : (b) .
6. .. is knows as Universal client side scripting language.
(a) Word (b) Powerpoint _ (c) Tally (d) JavaScript
Ans.: (d)
7. In .•...•..............scripting the script resides onthe client computer.
(a) Client Side (b) Server Side (c) My Side (d) Website
Ans.: (a)
8. In scripting the script resides on the web server.
(a) Client side (b) My side (c) Server Side (d) Website
Ans.: (c)
9. .. scripting does not need any server interaction.
(a) Server Side (b) Website (c) My side (d) Client Side
Ans.: (d)
TPSInformation Technology (Science) 3-19 Advanced JavaScript

10. . ; ; scripting communicates to the server.


(a) Client Side (b) Software Side
(c) Server Side , .. (d) Website
Ans.: (c)
11.. scripts are used for' validation purpose.
(a) Client Side (b) Server Side (c) Website (d) Web Browser
Ans.: (a)
12. . scripts requires web browseras on interface.
(a) ServerSide (b) Webpage (c) Website (d) Client Side
Ans. : (d)
13. . scripts requires web server software to execute.
(a) Client Side (b) Server Side (c) Peer (d) Home
Ans.: (b)
14. . is a JavaScript based open source frontend web framework
. developed for single page application. .
(a) VueJS (b) Response (c) Angular JS (d) React
Ans.: (c)
15. . is JavaScript based framework for building interactive user
interface.
~) VueJS (b) Response (c) React . (d) UueJS
Ans.: (a)
16. .................•................ consists of JavaScript libraries for building VI for single page
application and mobile application ..
(a) AngularJS (b) Vue JS (c) Respond (d) React
Ans.: (d)
17. Functions in JavaScript are declared using : Keyword.
(a) Function (b) Object (c) Method (d) var
Ans.: (a)

·1 . 3.2 Switch case and Looping Structures 1

18. .JavaScript has a built-in multiway decision statement known as .


(a) Condition (b) Switch (c) Break (d) Continue
Ans.: (b)
19. . refers to the execution of statement ot a group of statements of
code for a fixed number of times.
(a) Statement (b) Function (c) Iteration (d) Method
Ans.: (c)
TPSIniQrmation Technology (Science) 3-20 Advanced JavaScript

20. ......... loop combines initialization, condition and loop iteration in


single statement.
(a) for (b) Break (c) Switch (d) Continue
Ans.: (a)
21. . , means increment or decrement value of a running variable.
(a) Switch (b) Method (c) Object . (d) Iteration
Ans. : (d)
22. . -,.. statement is used to jump out of loop.
(a) Respond (b) Continue (c) Break (d) React
Ans. :(c)
23. What it is necessary to skip statement block and take the control at the beginning for
next iteration statement is used.
(a) Break (b) Continue (c) React (d) Response
Ans.: (b)

3.3 Objects in JavaScript


- 24. The keyword is used to create new object in JavaScript.
(a) Next (b) Wend (c) Loop (d) New
Ans. : (d)
25. An can group 'data together with functions needed to manipulate
it.
(a) Method (b) Function (c) Object (d) Response
Ans.: (c)
26. All tangible things are known as .
(a) Method (b) Objects (c) Function (d) Variable
Ans.: (b)
27. DOM stands for , .
(a) Document Object Model (b) Document One Model
(c) Design One Model (d) Document Object Manage
Ans.: (a)
28. The way in which HTML document content is accessed and modified is' called as

(a) Design Object Model (b) Develop Object Model


(c) Do Object Model (d) Document Object Model
Ans.: (d)

J'"
TPS Information Technology (Science) 3-21 Advanced JavaScript

29. property of DOM object returns the <head> element of the


document.·
(a) head (b)hody (c) title (d) link
Ans.: (a)
30. . :preperty of DOM object sets or returns title of the document.
(a) head (b) body (c) source (d) Title
Ans.: (d) .
31. . ~ property of DOM object returns URL of the HTML document.
(a) SRC (bY HREF (c) URL (d) LINK
Ans.: (c)
32. . method of DOM object writes HTML expressions or JavaScript
code to a document.
(a) writet) : (b) readt) (c) closet) (d) ReadOnlyf)
Ans.: (a)
33. method of DOM object adds a new line character after each
statement.
(a). closet) (b) writelru) (c) readt) (d) readOnlyt)
Ans.: (b)
34. Using method id property is used to find an element.
(a) write (b) URL (c) writeln (d) getElementByIdO
Ans.: (d)
305. The property is useful for getting html element and changing its
content.
(a) write (b) URL (c) innerHTML (d) writeln
Ans.: (c)
36. ..................•................ object is parent of all other objects.
(a) window (b) math (c) string (d) number
Ans.: (a)
37. . object represents an open window in a browser.
(a) Math (b) Array (c) String (d) Window
Ans.: (d)
38. property of window object sets or returns the name of the
window.
(a) location (b) name (c) document" (d) status e

Ans.: (b) .
TPS Information Technology (Science) 3-22 Advanced JavaScript

39. . ; property of window object returns the location object for the
window. .
(a) Window (b) Array (c) Math (d) Document
Ana: (d)
40. ........................•........ property of window .object returns the location object for the
window.
(a) name (b) location (c) status (d) closed
Ans.: (b)
41. . property of window object sets or returns the text in the status.
bar of a window. .
(a) name (b) location (c) status (d) closed
Ans.: (e)
42. . property of window object returns a Boolean valve indicating
whether a window has been closed or not.
(a) closed (b) status (c) document (d) name
Ans.: (a)
43. .. method of window object display the alert box containing
message with OK button.
(a) opent) (b) closet) (c) .alertf) . (d) promptt)
Ans.: (c)
44. .. method of window object displays the confirm dialog box
containing message with ok and cancel button.
(a) blurt) (b) confirnu) (c) printt) (d) focust)
Ans.: (b)
45. . : method 'of window object displays a dialog box to get input from the
user.
(a) alertt) (b) operu) (c) confirmt) (d) prompn)
Ans.: (d)
46. .. method of window object opens the new window.
(a) opent) (b) closet) (c) focust) (d) blurt)
Ans.: (a)
47. ..............•........ method of window object closes the current window.
(a) operu) (b) closet) . (c) blurt) (dy' alertt)
Ans.: (b)
4·8. .. . method of window object removes focus from the current window.
(a) printt) (b) operu) (c) prompu) (d) blurt)
Ans.: (d)
TPS InformationTechnology (Science) 3-23 Advanced JavaScript

49. . method of window object sets focus to the current window.


(a) focusf) (b) operu) (c) blurt) (d) close()
'Ans.: (a)
50. . method of window object prints the content of current window.
(a) alert() (b) setTimeoutO
(c) print() (d) openO
Ans.: (d)
51. .. : method of window object calls a function or evaluatesanexpression
after a specified number of milliseconds.
(a) opent) (b) setTimeout()
(c) .blurt) . (d) focust) .•
Ans.: (b)

3.4 JavaScript Events


52. are the actions done by users or an application that occurs on the
webpage .
(a) Events (b) Methods (c) Object (d) Functions
Ans.: (a)
53. . event occurs when user leaves or looses focus of an element.
(a) onchange (b) onblur (c) onfocus (d) onload .
Ans.: (b)
54. . event occurs when an element gets focus.
(a) onload (b) onblur (c) onfocus (d) onchange
Ans.: (c)
55. . event occurs when user changes content of an element or selects drop
down value.
(a) onblur' (b) onfocus . (c) onload (d) onchange
Ans.: (d)
56. ....: event occurs when user selects some text of an element.
(a) onselect . (b) onblur (c) onchange (d) onsubmit
Ans.: (a)
57. . event occurs when user clicks submit button.
(a) onblur (b) onchange (c) onfocus (d) onsubmit
Ans.: (d)
58. .. event occurs when user clicks reset button .
(a) onload .(b) onreset· (c) onchange (d) onsubmit
Ans.: (d)
TPS Information Technology (Science) 3-24 Advanced J avaScript

59. . event occurs when page/image has been loaded.


(a) onblur (b) onsubmit (c) onload (d) onunload
.t\ns. : (c) ,
60. . event occurs when document page has been unloaded or closes.
(a) onsubmit (b) onunload (c) onselect (d) onload
Ans.: (b)

3.5 JavaScript built-in Objects


61. . ; object is
used to store or manipulate text.
(a) Math (b) Date (c) Number (d) String
Ans.: (d)
62. . : property of string object returns number of characters in a string.
(a) value (b) length (c) object (d) leI)'
Ans.: (b)
63. method of string object returns the character at the specified
position.
(a) indexOfO (b) substrt) (c) charAtO (d) trimt)
Ans.: (c)
64. . method of string object returns the index of the first occurrence
of specified character in given string.
(a) indexOfO (b) substr() (c) substrmgt) (d) trimt)
Ans.: (a)
65. method of string object returns the index of last occurrence of
specified character in given string.
(a) substrt) (b) charAtO (c) lastIndexOfO (d) trimt)
Ans.: (c) ,
66. . ~ method of string object removes white space from both sides of a
string.
(a) trimt) (b) substrt) (c) indexOfO (d) substringf)
Ans.: (a)
67. .. method of string object converts a string to lower case.
(a) toUpperCaseO (b) substrt)
(c) trim() (d) toLowerCaseO
Ans.: (d)
68. . method of string object converts a string to upper case.
(a) toLowerCaseO (b) toUpperCaseO
(c) trimO (d) substringt)
Ans.: (b)
TPS Information Technology (Science) 3-25 Advanced JavaScript

69. The built in object includes mathematical constants and functions.


(a) String (b) Date (c), Math (d) Math
Ans.: (c)
70. . ; ; method of math objectreturns the absolute value of a number.
(a) absO (b) cbrt() (c) min() (d) sqrtO
Ans.: (a)
71. . method of Math objectreturns the cube root of a number.
(a) sqrtt) (b) maxf) (c) ceilt) (d) cbrt()
Ans.: (d)
72. . : method of math object returns the next integer grater than or
equal to a given number.
(a) abs() (b) cbrt() (c) ceil() (d) floor()
Ans.: (c)
73. . method of math objectreturns the next integer less than or equal to a
given number.
(a) abst) (b) floort) (c) min() . (d) maxt)
Ans.: (b)
74. . ~ method of math object returns the highest valued number in a list
of numbers.
(a) min() (b) pow() (c) .sqrtO (d) max()
Ans.: (d)
75. .. method of math objectreturns the lowest valued number in a list of
numbers.
(a) powO (b) max() (c) min() (d) floort)
Ans.: (c)
76. . method of math object returns the base to the exponent power.
(a) powO (b) floor() . (c) abst) (d) cbrtt)
Ans.: (a)
77. .. method of math object returns a random number between 0
and l.
(a) abs() (b) randomO (c) powO (d) sqrt()
Ans.: (b)
78. .. method of math objectreturns the square root of a number.
(a) cbrtt) (b) ceilO (c) sqrtO (d) abst)
Ans. :(c)
79. .. objectis used to create date and time values.
(a) math (b) Date (c) string (d) Number
Ans.: (b)
TPS Information Technology (Science) 3-26
Advanced JavaScript

80. . , method of date object returns the day of the month.


(a) getDayO (b) getHoursO (c) getMonthO (d) getDateO
Ans.: (d)
81. . , method of date object returns the day of the week.
(a) getDayO .(b) getHouisO (c) getMonthO (d) getDateO
Ans.: (a)
82. . method of date object returns the year.
(a) getDateO (b) setSecondsO (c) getFullYear() (d). setDate()
Ans.: (c)
83. . method of date object returns the hour.
(a) getHoursO (b) nowi) (c) getTimeO (d) setHoursO
Ans.: (a)
84. . : method of date object returns the minutes ..
(a) getHoursO (b) getMonthO (c)nowO (d) getMinutesO
Ans.: (d)
. 85. .................•.................. method of date object returns the month.
(a) getSecondsO (b) getMonthO
(c) setHoursO (d) getTimeO
Ans.: (b)
86. . method of date object returns the seconds.
(a) getSecondsO . (b) getDateO
(c) getMonthO (d) nowO
Ans.: (a)
87; ; method of date object sets the day of the month.
(a) setHoursO (b) setTimeO (c) setDateO (d) setMinutesO
Ans.: (c)'
88. . method of date object sets the full year.
(a)setTimeO (b) setFullYearO (c) nowO (d) getMonthO
Ans..: (b)
89. . method sets the hours of a date object.
(a) nowO (b) getDayO (c) getMonthO (d) setHoursO
Ans.: (d)
90. .. method sets the minutes of a date object.
. (a) setMinutesO (b) getDayO (c) nowO (d) setHoursO
Ans.: (a)
TPS Information Technology (Science) 3-27 Advanced JavaScript

91. . ; method sets the month of a date object.


(a) sefTimef) (b) getDayO (c) setMonthO (d) getDateO
Ans.: (c)
92. .. method sets the seconds of a date object.
(a) setHoursO (b) setSecondsO (c) setMonthO (d) setTimeO
Ans.: (b)
93. .. method sets a date to a specified number of milliseconds after/before Ian 1,
1970.
(a) seffimet) (b) setSecondsO' (c) nowO (d) setHoursO
Ans. : (a) .
94. .. object helps us to work with number.
(a) Math (b) Number (c) Array (d) Date
Ans.: (b)
95. .. property of Number object returns the largest minimum value .
.
' .
(a) MAX_VALUE . (b) NaN
(c) MIN_ VALUE (d) Fixed
Ans.: (c)
96. .. property of number object represents not a number value.
(a) NaN (b) Value (c) Fixed (d) Index
Ans.: (a)
97. Method of Number object determines whether the given value is a
. integer.
(a) parsel'loatt) (b) isf'ixedt) (c) isIntegerO (d) parseIntO.
Ans.: (c)
98. . ; method of number object determines whether the given value is
Integer.
(a) parseFloatO (b) parselntt) (c) isFixedO (d) NaN
Ans.: (a)
99. .. method of number object converts the given string into a integer
. )
number.
(a) isIntegerO (b) isf'ixedf) . (c) parseFloatO (d) parselntt)
Ans.: (d)
100. method of Number object returns the string that represents a
number with exact digits after a decimal point.
(a) isIntegerO (b) isFixedO (c) parselntt) (d) parseFloat()
Ans.: (b)
TPS Information Technology (Science) 3-28
Advanced JavaScript
101. How to declare string variable?
(a) var str - new str 0; (b) var a = I. T.;
(c) a = str. Str;
(d) var str = "Information Technology";
Ans.: (d)
102. An , is an object that can store a collection of items .
. (a) Array (b) String. (c) Number (d) Math
Ans.: (a)
103. . : are used to hold more than one value at a time.
(a) Number (b) Math (c) Array (d) Date
Ans.: (c)

104.. To create an array in JavaScript the correct method is .


(a) var d = new d [one, two, three] (b) var d = (one, two three)
(c) var arr = ["One", "Two", "Three"] (d) var d = (One), (Two), (Three)
Ans.: (c)
105. To access and set the items in any array ;.. is referred.
(a) indexnumber (b) element
(c) array (d) object
Ans.: (a)
106. The index of the first element of an array is .
(a) One (b) Two (c) Three (d) Zero
Ans.: (d)
107. . property of Array object represents the zero based index of the match in the
string.
(a) index (b) length (c) NaN (d) Close
Ans.: (a)
108. . property of Array object reflect number of elements in array.
.. (a) index (b) length (c) NaN (d) Value
Ans.: (b)

109. . ; method of Array object joins two or more arrays, and returns a copy of the
joined arrays.
(a) findj) (b) concan) (c) indexOfO (d) popt)
Ans.: (b)

110. . method of Array object copies array elements within the array, to and from
specific positions.
(a) findO· (b) search() (c) copyWithin() (d) indexOf()
Ans.: (c)
TPS Information Technology (Science) 3-29 Advanced JavaScript

111. . method of Array object returns the value of the first element in an array
that satisfies a test in testing.
(a)concatO (b) popt) (c) pushO' (d) findt)
Ans.: (d)
112. . method of Array object calls a function for each array element.
(a) concan) (b) forEachO (c)popO (d) pushf)
Ans.: (b)
113. . method of Array object search the array for an element and returns its
position. .
(a) concatt) (b) forEachO (c) indexOfO (d) popt)
Ans.: (c)
114. . method of Array object checks whether an objectis an array.
(a) findf) (b) popt) (c) forEachO (d) isArrayO
Ans.: (d)
115. . method of Array object removes the last element of an array and returns that
element.
(a) popO (b) puslu) (c) findt) (d) reverser)
- Ans.: (a)
116; method of Array object add new elements to the end of an array, and
returns the new length.
(a) popO (b) pusht) (c) sortt) (d) findt)
Ans.: (b)
117. . method of Array object reverses the order of the elements in an array.
(a) findt) (b) isArrayO (c) popt) (d) reverser)
Ans. : (d)
118. . method of Array object sorts the elements of an array.
(a) c6ncatO(b) sortt) (c) popt) (d) find 0
Ans.: (b)

-
3.1 Introduction
1. Features of JavaScript are : .
(a) It needs special software
.(b) JavaScript is light weight scripting language'
(c) Cannot create new function
(d) It is object oriented scripting
Ans. : (b), (d)
· TPS Information Technology (Science) 3-30 Advanced JavaScript

2. There are two types of Scripting .


(a) Server side (b) Myside (c) Browser side (d) Client side
Ans. : (a), (d)
3. Client Side Scripting ': .
(a) These scripts are paced inside ~L document
(b) In this type the script resides on Client Computer.
(c) In this type, the script resides on web server
(d) To execute script it must be activated by client then it is executed on web
server.
Ans. : (a), (b)

3.2 Switch case and Looping Structures


4. Types of loops in JavaScript are .
(a) for .loop (b) while .loop
(c) for next (d) while wend
Ans, : (a), (b)
5. Correct method of for loop are .
(a) for(i=1;i<=5;i++) (b) for (i = 1, i! = 4);
{
document. write(i); document.write (i);

(c) for(i=1;i<=5;i++) (d) [i -1, ic = 5,i ++)

document.write1n(i); document.write (i);


}
Ans. : (a), (c)

3.3 Objects in JavaScript


~.

6. JavaScript supports. following types of objects .


(a) Variables (b) built-in objects
(c) User defined objects (d) loops
Ans. : (b), (c)
7. Following are the built in objects in JavaScript .
(a) Math (b) Time (c) Array (d) ·Month
Ans. : (a), (c)
TPS Information Technology (Science) 3-31 Advanced JavaScript

8. Following are the properties of Document Object Model .


(a) Src (b) head (c) URL (d) title
Ans. : (a), (c)
9. Following are the methods of Document Object Model .
(a) body (b) writet) (c) URL (d) writeInO
Ans. : (b), (d)
10. Following are the properties of Window object .
(a) name (b) location (c) alertt) (d) confirmO
Ans. : (a), (b)
11. Following are the methods of Window object "
(a) operu) (b) status (c) closed (d) closet)
Ans. : (a), (d)
12. confirmt) method of window object displays confirm dialog box containing message
with '" and button.
(a) GO (b) OK (c) Cancel (d) Click
Ans. : (b), (c)

3.4 JavaScript Events


13. Following are the event handlers in JavaScript ;
(a) onsubmit (b) writet) (c) onchange (d) writelru)
Ans. : (a), (c) .

3.5 JavaScript built-in Objects


14. Following are the methods of string objects .
(a) chartAtO (b) width (c) length (d)' trimO
Ans. : (a), (d)
15. To find the highest and lowest valued number in a list of numbers which Math
Object methods are used in JavaScript .
(a) ceilt) (b) sqrtO (c) maxt) (d) miru)
Ans. : (c), (d)
16. Following are the methods of Math objects .
(a) substrt) (b) absr) (c) trimO (d) randomf)
Ans. : (b), (d)
17. In JavaScript following methods of String object returns the characters you
specified.
(a) substringt) (b) indexOfO (~) substrf) (d) lastIndexOfO
Ans. : (a), (c)
TPS Information Technology (Science) 3-32 Advanced JavaScript

18. Different ways to create new Date object are .


(a) var d == new Dater): (b) vard = DateO
(c) var d = month(} (d) var d == new Date (DateString);
Ans. : (a), (d)
19. Following are the methods of Date object .
(a) setDateTimeO (b) getDateTimeO
(c) getTimeO (d) getDayO
Ans. : (e), (d)
20. Following properties of Number Object returns the largest minimum and maximum
value .
(a) MIN_ VALUE (b) MAX_VALUE
(c) toLowerCaseO (d) toUpperCaseO
Ans. : (a), (b)
21. Following are the properties of Number Object in Javascript , .
(a) lowercase (b) Uppercase (c) NaN (d) MAX_YALUE
Ans. : (c), (d)
22. Following are the methods of Number of object in JavaScript ; .
(a) NaN (b) parselnn) (c) isFixedO (d) toLowercaseO
Ans. : (b), (e)

23. Following methods are used to create Array variable in JavaScript .


(a) var a = "One, two",
(b) var - a ["One", "Two", "Three"];
(c) array a = ("One", "Two"),
(d) var a = new Array ("One", "Two", "Three");
Ans. : (b), (d)
24. Following are the properties of Array object in JavaScript .
(a) index (b) isFixed (c) concat (d) length
Ans.: (a), (d)
25. Following are the methods of Array object in JavaScript .
(a) index (b) length (c) forEachO - (d)isArrayO
Ans. : (e), (d)
26. Following methods of Date object returns the number of miliseconds
(a) getTimeO (b) getDateO (c) getTimeO (d) nowO
Ans. : (c), (d)
TPS Information Technology (Science) 3-33 Advanced [avabcript

27. The Date objectis used to create and values.


(a) date (b) string (c) Time (d) Number
Ans. : (a), (c) .--
28. The built-in Math objectincludes mathematical and ........•.........
(a) constants (b) functions (c) objects (d) values
Ans. : (a), (b)

3.1 Introduction
1. Features ofJavaScript are .
(a) Need of special software (b) It can handle date and time effectively
(c) It cannot create new functions (d) It can not create new furictions
(e) It supports event based programming
(f) It is platform dependent scripting language
Ans. : (b), (c), (e)
2. Server Side Scripting .
(a) It is used as front end •
(b) Doesnot need any server interactions
. . J •

(c) Involves languages such as HTMLS,JavaScript etc.


(d) It is used as back end (e) Special software is required to execute
(f) Script resides on web server
Ans. : (d), (e),(f)
3.. Popular Framework /libraries •.....•••.......
(a) HTML (b) Angular JS (c) Network Frame
(d) VueJs (e) React (f) Switch Case
Ans. : (b), (d), (e)

3.2 Switch case and Looping Structures


4. Java Script looping statements are .
(a) for loop (b) switch case
(0) while loop (d) if
(e) if else if (f) Do while loop
Ans. : (a),.(c), (f)
TPS Information Technology (Science) 3-34 Advanced JavaScript

3.3 Objects in JavaScript


5. JavaScript built in objects are .
(a) Math (b) String (c) Number
(d) Time (e) Month (f) Year
Ans. : (a), (b), (c)
6. Properties of Document Object Model are .
(a) write (b]' writein (c) title
(d) URL (e) writein () (f) head
Ans. : (c), (d, (f)
7. Methods of Document Object Model are .
(a) writet) (b) getElementByIdO (c) URL
(d) head (e) SRC (f) writelnO
Ans. : (a), (b), (f)
8. Methods of Window Object are .
(a) Name (b) blurt) (c) location (d) focust)
(e) closed (f) setTimeOutO
Ans. : (b), (d), (f)
9. Select three correct properties of Window Object ..•... , .
(a) dose (b) name (c) print (d) status
(e) open (f) closed
Ans. : (b), (d), (f)

I .~~_~.4_Java~c!ipt _Events .
10. Select three correct event handlers in JavaScript .
(a) close (b) open '(c) onsubmit (d)onchange
(e) onunload (f) write
Ans. : (c), (4),(e)

3.5 JavaScript built-in Objects


11. Methods of string object are , .
(a) substrt) (b) length (c) toLowerCaseO
(d) abs (e) indexOfO (f)' ceil
Ans. : (a), (c), (e)
12. Methods of Math object are, .... ,.. ,... '" .
(a) sqrtt) (b) substrt) (c) indexOfO (d) random ()
(e) closeO(f) floor ( )
Ans. : (a), (d), (f)
TPS Information Technology (Science) 3-35 Advanced JavaScript

13. Methods of Date objects are .


(a) trimt) (b) getDayO (c) getHoursO (d) indexOfO
(e) get'Iimet) (f) chanAtt)
Ans. : (b), (c), (e)
14. Different ways to create new date object are .
(a) var d = new Date(); (b) var d = Datet)
(c) var d = date newO (d) var d = new Date(DateString);
(e) var d = new Date (date String) (f) var d = new Date(miliseconds);
Ans. : (a), (d), (f)
15. Properties of Number objects are .
(a) length (b) onblur
(c) onfocus (d) MIN_ VALUE
(e) MAX,--VALUE (f) NaN'
Ans. : (d), (e), (f)
16. Select three correct methods of Number object .
(a) NaN (b) parseFloatO (c) isFixedO
(d) length (e) index (f) islntegerO
Ans. : (b),(c), (f)
17. Methods of Array object are .
(a) sortt) (b) indexoft) (c) isf'ixedt)
(d) forEachO (e) islntegert) (f) parselntt)
Ans. : (a), (b), (d)

3.2 Switch Case and Looping Structures


(I)
.
A B
(1) Switch case (a) Combines initialization, condition and loop iteration
(2) For loop (b) Skip statement block and take the control at the beginning
for next iteration
(3) Break (c) Server side script
(4) Continue (d) Used to jump out of loop
(e) Decision statement
-- -_ .._- -- - - -- -_ ... --_.. _ .. --- --- ~~ --_ ... ~ -- --

Ans. : (1) - (e), (2) - (a), (3) ~ (d), (4) - (b)


*. '
- TPS Information Technology (Science) 3-36 - Advanced JavaScript

3.3 Objects in JavaScript

(I)

A B
(1) Head - (a)- Returns title of the document
(2) Title (b) Returns <body> <img> elements
(3) URL (c) Returns URL of document
(4) Body,img (d) Returns <head> element of the document
(e) Writes expression
Ans.: (1) - (d), (2) - (a), (3) - (c), (4) -(b)
(II)

A B
(1) OOM (a) Defines logical structure of document
(2) writet) (b) Client Side Script
(3) writelnO (c) In which id property is used to find element
(4) getElementByldO (d) Writes JavaScript Code
(e) Writes JavaScript code to a document
after each statement
' .
by adding new line
-~-. - --- - --- -_ ... _-------- -- -- - - - -

Ans. : (1) - (a), (2) - (d), (3) - (e), (4) - (e)


(III)

A B
(1) Location (a) Sets name of the window
(2) Document (b) Returns Boolean value indicating whether a window
(3) Status (c) Returns document object of window
(4) Closed (d) Returns the text in the status bar of a window
--"-
(5) --
Name--
(e) Returnsthe location object for the window -
Ans. : (1) - (e), (2) - (e), (3) - (d); (4) '- (b);(5),- (a)
(IV)

A B
(1) Window object (a) Displays dialog box containing message with ok and
cancel. button
(2) alertf) (b) Opens the new window
(3) confirmt) (c) Displays dialog box to get input from the user
(4) promptO (d) Parent object of all 'other objects
(5)
-
opent) (e) Displays box with ok button
Ans. : (1) - (d), (2) - (e), (3) - (a), (4) - (c), (5) - (b)
TPS Information Technology (Science) 3-37 Advanced JavaScript,

(V)
i
A B I
I

(1) closet) (a) Removes focus from the current window I

(2) blurt) (b) Prints the content of current window

(3) foeust) (c) Closes the current window

(4) prinn) (d) Calls a function after specified number of miliseconds

(5) setTimeOutO (e) Sets focus to the current window


Ans.: (1) - (d, (2) - (a), (3) - (e), (4) - (b), (5) -(d)

3.4 JavaScript Events


(I)
.
A B

(1) On blur (a) Occurs when user changes content of an element

(2) On focus (b) Occurs when user selects some text of an element

(3) On change (c) Occurs when an element get focus

(4) On select (d) Occurs when user leaves field or losses focus of an element

(e) Closes window


~-.- - -- - - -- -
Ans.: (1) - (d), (2) -Cd, (3) - (a), (4) - (b)
(II)

A B
I
(1) Onsubmit (a) . Occurs when user clicks on reset button

(2) Onreset (b) Prints the contents of the window

(3) Onload (c) Occurs when document page has been unloaded or closes

(4) Onunload (d) Occurs when user clicks submit button

(e) Occurs when page image has been loaded


Ans. : (1) - (d), (2) -,(a), (3) - (e), (4) - (c)
·TPSInformation,!echnology (Science) 3-38 Advanced JavaScript

[ 3.5 JavaScript built-in Objects

(I)
.A.
-.
B
(1) Length (a) Returns the character at the specified position
(2) chartAtO (b) Returns the index of last occurrence of specified character in
given story
(3) indexOfO (c) Returns the characters you specified
(4) lastIndexOfO (d) Returns the index of the first occurrence of the character
(5) substrt) (e) Returns a number of character in a string
- - _. - - - - -- -- _ .. -- --_. - -- - -

Ans. : (1) - (e), (2) - (a), (3) - (d), (4) - (b), (5) - (c)
(II)
A B
(1) substringt) (a) Returns the characters you specified
(2) trimO (b) Converts a string into lower case
(3) toLowerCaseO (c) Returns length of string
-
(4) to UpperCaseO (d) Converts the string into Upper case
(e) Removes white spaces from both sides of a string
_
----_. --- .. -- _-
--_ ..- ----- -- ~-- -----_ ..

Ans, : (1) - (a), (2) - (e), (3) - (b), (4) - (d)


.(III)
A B :

(1) absO (a) Returns next integer greater than or equal to a given number -,
(2) cbrtO (b) Returns the highest valued number in a list of NUmbers
(3) ceilt) (c) Returns the absolute value of a number
(4) floorO (d) .Returns the cube root of a number
(5) max() (e) Returns next integer less than or equal to a given. number
Ans, : (1) - (c),(2) - (d), (3) -(a), (4) -(e), (5) - (b)
(IV)

A B
-
(1) mirif) (a) Returns the base to the exponent power
(2) powO (b) Returns the square root of a number
(3) randomt) (c) Returns the cube root of a number
(4) sqrtO (d) Returns a random number between 0 and 1
(e) Returns the lowest valued number in a list of number'
--

Ans. : (1) - (e), (2) ..•.(a), (3) - (d), (4) - (b)


. TPS information Technology (Science) 3-39 Advanced JavaScript

(V)

A B
(1) getbateO (a) Returns the year
(2) getDayO (b) Returns the Time
(3) getFullYearO (c) Returns the day of the week
(4) getHoursO (d) Returns the hour
(e) Returns the day of the month
Ans. : (1) - (e), (2)- (c), (3) - (a), (4) - (d)
(VI)
I
A B I

(1) getMiriutesO (a) Returns the number of miliseconds I


(2) getMonthO (b) Returns the minutes
(3) getSecondsO (c) Sets the month
(4) getTime() (d) Returns the month
(e) Returns the seconds
Ans. : (1) - (b), (2) - (d), (3) - (e), (4)- (a)
(VII)
A B
(1) setHoursO (a) Sets the days of the month ofa date object
(2) -nowt) (b) Returns the year
(3) . setDateO (c) Set the full year of a date object
(4) setFullYearO (d) Returns the number of miliseconds
I . (e) Sets the hours of a date object
Ans. : (1) - (e), (2) - (d), (3) - (a), (4) - (c)
(VIII)

A B
(1) setlvlinutesl) (a) Sets the month of a date object
(2) setMonthO (b) Set a date to a specified number of miliseconds
(3) setSecondsO (c) Returns day of the week
(4) set'I'imer) (d) Set the minutes of a date object
(e) Sets the seconds of a date object
Ans. : (1) - (d), (2) - (a), (3) - (e), (4) - (b)
TPS InformationTechnology (Science) 3-40 Advanced JavaScript

(IX)
A B
(1) MIN_VALUE (a) Represent not a Number value
(2) MAX_VALUE (b) Determines whether the given value is a Integer
(3) NaN (c) Returns the largest minimum value
(4) isInteger( ) (d) Converts string into Floating point number
(e) Returns the largest max~urn ~~ue
Ans. : (1) - (c), (2) - (e), (3) - (a), (4) - (b)
(X)

A B
(1) parseFl6atO (a) Used to create date and time values
(2) parselntl) (b) Returns the string that represents a number with exact digits
after a decimal point
(3) isFixed() (c) Converts a given string into a floating point number
(4) Date object (d) Converts the given string into integer number
Ans. : (1) - (e), (2) - (d), (3) - (b), (4) - (a)
(IX)
A B
(1) concatt) (a) Returns the value of the first element in an array that satisfies a
test .
(2) copyWithinO (b) Search the array for an element and return its position
(3) findt) (c) Calls a function for each array element
.(4) forEachO (d) Joint two or more arrays and returns a copy of joined array
(5) indexOfO (e) Copies array elements within the array, to and from specified
positions.
- -- -

Ans. : (1) .;..(d), (2) - (e), (3) - (a), (4) - (e), (5) - (b)
(XII)
A B
(1) isArrayO (a) Adds a new elements to the end of an array, and returns the new
length
(2) popt) (b) Sorts the elements of an array
(3) PushO (c) Reverse the order of the elements in an array
(4) reverset) (d) Checks whether an object is an array
(5) sort( ) (e) Removes the last element of an array, and returns the element
--- _ -- - - .. - -- -- --- -

Ans. : (1) - (d), (2) - (e), (3) -(a), (4) - (c), (5) - (b)
TPS Information Technology (Science) 3-41 Advanced JavaScript

3.2 Switch case and Looping Structures

Switch Case:
The switch statement is used to perform different actions based on different
conditions, .
Syntax
switch( expression)

case x:
/ / code- block
break;
case y:
/ / code block
break;
default:
/l code block

Example: Programto print 4 different Greeting messages using switch case


Coding:
<html>
<script type='fext/javascript">
varmsg=2;
switch(msg)
{
case 1:
lt
alert("Hello );

break;
case 2:
alert("Welcome");
break;
case 3:
alert("How r u");
break;
TPS Information Technology (Science) 3-42 Advanced JavaScript
.~--------------------------------------~
case 4:
alert("Take care Good bye"):
break;
default:
alert("Invalid choice");

</script>
</html>
Coding:
x

.... ,
C
.
(i) File· i .E:/Xll%20SG%20IT%21L. * -e
This page says
Welcome

Looping statement: Loops can execute a block of code a number of times.


For Loop
Syntax
The for loop has the following syntax:
For (initialization; condition; iteration)

code block to be executed


}

Example: Program to print numbers from 1 to lOusing for loop.


Coding:
<htmb-
<script type='fext/javascript''>
TPS Information Technology (Science) 3-43 Advanced JavaScript

var i;
for(i=l;i<=lO;i++ )

document.writeti+'<br>"):
} .

</script>
</html>
Output:

1
2
3
4
5
6
7
8
9
10'

Note: "language" attribute of <script> tag is replace by "type" attribute in all programs
as it is standardised.

> . While Loop: The while loop loops through a block of code as long as a specified
condition is true.
Syntax :
Initialization;
while (condition)

code block to be executed


r
Example: Program to check whether the entered number is Odd or Even.
<html>
<body>
<form name=frm'l">
TPS Information Technology (Science) 3-44 Advanced JavaScript

Enter a Number
<input type="number" nam~~It1"><br><br>
<input type="button" name="bl" value="Odd Even" onClick=levenO">
</form> '
</body>
<script type="text/javascript">
function event)
{
vara;
a=frml.t1.value;
if(a%7==O)
alert("Number is even");
else
alert("Number is odd");
}
</script>
</htm1>
'Output :,

> Do while Loop : The do/while loop is a variant of the while loop. This loop will
execute the code block once, before checking if the condition is true, then it will
repeat the loop as long as the condition is true.
Syntax:
Initialization;
do {
/ / code block to be executed
}
while (condition);
TPS Information Technology (Science) 3-45 Advanced JavaScript

~ Example: Program to print numbers from 1- 10 using do while loop.


Coding:
<html>
<script type="text/javascript">
vat i;
i=l~
do

docurnent.writefi+l'<br>"):
i++;

while(i<=lO);
</script>
</html>
Output:

2
3
4
.5
6
7
8
9'
10

~ Break Statement: The break statement" jumps out" of a loop.


Program to check whether the number is prime number of not.

Coding:
<html>
, <body>
<form name="frml">
Enter a Number

,-
TPS Information Technology (Science) 3-46 Advanced JavaScript

<input type='fext" name=Tlc-xbrs-cbr>


<input type="button" name="bl" valuee-'Prime Number"

onClick="prirneO">
</form>
</body>
<script type="text/javascript">
function primer)

var i,a,p;
a=parseInt( frml. tl. value);
.p=l;
for(i=2;i<a;i++ )

if(a%i===O)
p=O;
break;

if(p==l)
alert("Number is Prime number");
else
alert("Number is not a Prime number");

</script:>
</htrnl>

Output:

/
TPS Information Technology (Science) 3-47 Advanced JavaScript

I 3.3 Objects in JavaScript I·


JavaScript is an object based scripting language. A [avaScript object is an entity
having properties and methods.Prosperities and methods of object's are accessed
with ":" operator. JavaScript supports two types of objects built-in objects and user
defined objects. .
DOM(Do~ument 'Object Model) :
When a web page is loaded, the browser creates Document Object Model of the
page.
The DOM is a W3C (World Wide Web Consortium) standard. "The W3C Document
Object Model (DOM) is a platform and language-neutral interface that allows
programs and scripts to dynamically access and update the content, structure, and
style of a document."
Following are the predefined methods and properties for DOM object :
Property .Description
head Returns the <head> element of the document
Title Sets or returns title of the document.
URL Returns full URL of the HTML document.
body,img Returns <body>, <img> elements respectively.
Method Description
writet) Writes HTMLexpressions or JavaScript code to a
document.
writelnO Same as write(), but adds a newline character after
each statement. ,
getElementByIdO There are many ways of accessing form elements, of
which the easiest is by getElementByldO method. In
which id property is used to find an element.
Example:
<html>
<script type="text/javascript">
function domt)

var s=="<h2style=color-red>":
var t="DocumentObject Model";
var c=" </h2>";
document.getElementByld('para').
TPS Information Technology (Science) 3-48 Advanced JavaScript

innerHTML=s+t+c;

</script>
<body>
<p id="para">Welcome to mywebsite</p>
<form>
<input type="button" nameeb.l" value="Change Font" onClick="dorit()">
</form>
</body>
</html>
Output:
Before Button dick After Button Click

WelcO!lle'to my website

~ Window Object : Window object is the parent object of all other objects. It
represents an open window in a browser. An object of a window is created
automatically by the browser. Folfowing are the methods and properties of
Window objet ..
Property Description
name Sets or returns the name of a window.
location Returns the Location object for the window.
document. Returns the Document object for the window.
status Sets or returns the text in the status bar of a window.
closed Returns a Boolean value indicating whether a window has' been
closed or not.
TPS Information Technology (Science) .3-49 Advanced JavaScript

Method Description
alertt) Displays the alert box containing message with ok button.
confirmt) Displays the confirm dialog box containing message with ok and
cancel button.
promptO Displays a dialog box to get input from the user.
operu) Opens the new window.
closet) Closes the current window.
blurt) Removes focus from the current window.
focusO Sets focus to the current window.
prinn) Prints the content of current window.
set'I'imeoutt) Calls a function or evaluates an expression after a specified number
. of milliseconds .
- - .. -.~-.~- ---_ .. _ ... _--_ _-
.. - - -- ----

~ Program to make use of some properties of Window object


Coding:
<html>
<script type=ttext/javascript">
window.status="hello";
var a= window.open("", "My New Window", "width=200,height=100");
• a.document.writef'<brc-cbre-This window's name is: " + a.name):
</script> .
</html>
Output:
TPS Information Technology (Science) 3-50 Advanced JavaScript

~ Programto display alert, prompt and confirm methods of Window Object.


Coding:
<html>
<script type="text/javascript">
varn;
n=prompt("Enter your Name");
alertt'Your Name is "+n);
confirm("Press OK");
</script>
</html>
Output :-

••
.( a ,,;::;:;1
¥DIJ[Noam£'IsBum

~ Program to change background colour of the page in every 4 seconds, there


should be altleast 4 distinct colours except default colour.
Coding:
.<html>
<script typee'fext/javascript"» ..
function colorl ()

document.bgColore'tred":
window.setTimeout("color20",4000);

function color20 .

document.bgColor="green";
window.setTimeout("color30",4000);
TPS Information Technology (Science) 3-51 Advanced J avaScript

.function color30

documen.t.bgColor="blue";
window:setTimeout("color40",4000);

function color40

document.bgColor="yellow";
window.setTimeout("colorlO",4000);
.}

</script>
<body>
<form name="frml ">
<center>
<input type=''button'' name="bl" value="Change Colors"
onMouseOver="colorlO">
</center>
</form>
</body>
</htmi>
Output:
'" cO~Of,htm~
TPS Information.Technology (Science) 3-52 Advanced JavaScript

~ Program to make use of open, close-and print methods of Window object.


Coding:
<html>
<script type="text/javascript">
window.open("http://www.grnail.com"); / /will open gmail website
window.print(); .
window.closet): / / will close the current window
</script>
</html>

3.4 JavaScript Events

~ Events are the actions done by user that occurs on the web page. Following are
some of the events used with form objects.
Event handler Description
onblur It occurs when user leaves field or losses focus of an element.
onfocus It occurs when an element gets focus.
onchange It occurs when user changes content of an element. or selects
dropdown value. E.g .. for textbox, password, select box, textarea
etc.
onselect It occurs when user selects some text of an element.
onsubmit It occurs when user clicks submit button.
onreset It occurs when user clicks reset button.
onload It occurs when page/image has been loaded.
onunload It occurs when document/page has been unloaded or closes.
----

3.5 JavaScript built-in Objects J


~ JavaScript has several built-in objects. These objects provide different-properties
and methods that are useful while creating web pages.
String Object :
String is used to store characters of text with single or double quotes. It is used to
store and manipulate text.
Property Description
Length Returns the number of characters in a string
TPS Inforrriation Technology (Science) 3-53 Advanced JavaScript

Method Description
char.Att): Returns the character at the specified position (in Number).
indexOfO Returns the index of the first occurence of specified character
in given string, or -1 if it never occurs, so with that index you
can determine if the string contains the specified character.
lastIndexOfO Returns the index of the last occurrence of specified character
in given string.
substrO Returns the characters you specified: (14,7) returns 7
characters, from the 14th character.
substringO Returns the characters you specified: (7,14) returns all
characters between the 7th and the 14th.
trimf) The trimt) method removes whitespace from both sides of
a String
toLowerCaseO Converts a string to lower case
toUpperCaseO Converts a string to upper case - -

~ Example: Program to make the use of string object.


Coding:
<html>
<script type="text/javascript">
var n=" Information Technology ";
document.write("<br><br>String is "+n);
document.write("<br><br>Length of String is "+n.length);
document.write("<br><br>Element at 4th place is "+n.charAt(3»;
document.writet'<brc-cbrc-Pirst occurrence of 0 is "+n.indexOf(,o'»;
document.writei'<brc-cbrc-Last occurrence of 0 is "+n.lastIndexOf('o'»;
document.write("<br><br>Display the characters from 3 to 7 place
"+n.substr(3,7»;
document.write("<br><br>Substring is "+n.substring(3 7»;
j

document.write("<br><br>Remove spaces from the string "+n.trim());


document.write(" <br><br> Lowercase conversion" Tn.toLowerCaseO);
document. write(" <br> <br>Uppercase conversion" Tn.toUpperCaseO);
. -c/script»
-c/html»
TPS Information Technology (Science) 3-54 Advanced JavaScript

Output: x
". 5tring,ht'11i

.~ "'" C (DFiie

String is Information Technology

Length of String is 26

Element at 4th place is n

First oceurance of 0 is 5

Last occurance of 0 is 21

Display the characters from 3 to 7 place nformat

Substring is nfor

Remove spaces from the string Information Technology

Lowercase conversion information technology

Uppercase conversion INFOR.i.\1ATION TECHNOLOGY

Math Object :
The math object includes mathematical constants and functions. Following table
consists list of Math objects. .
Method Description
absO Returnsthe absolute value of a number:
cbrt(x) Returns the cube root of a number.
ceil(x) Returns the· next integer greater than or equal to a given
number (rounding up).
floor(x) Returns the next integer less than or equal to a given number
(rounding down).
max(x, y, ...) Returns the highest-valued number in a list of numbers.
min(x, y, ...) Returns the lowest-valued number in a list of numbers.
pow(x, y) Returns the base to the exponent power, that is, xy.
random(x) Returns a random number between 0 and 1 (including 0, but not 1).
sqrt(x) Returns the square root of a number,
- .. ------------------- - ---
TPS Information Technology (Science) 3-55 Advanced JavaScript

~ Program to make use of Math Object


Coding:
-chtrnl>
<script type="text/javascript">
var x=-25.667;
vary=lO;
var z=Z;
document.writef'<br> Value of X is "+x);
document.writet'<br> Value of Y is "+y);
document.write("<br><br> Absoulte value of x is "+Math.abs(x»;
document.writef<brc-cbr> Cube Root of y is "+Math.cbrt(y»;
docllment.write("<br><br>Highest value among x and y is "+Math.max(x,y»;
document.write("<br><br>Lowest value among x and y is "+Math.min{x,y»;
document.writef'<brc-cbrc-Power is "+Math.pow(x,z»;
document.write("<br><br>Square Root of y is "+Math.sqrt(y»;
</script>
</htm1>
Output:
" math,html x

<t,. ") C

Value of X is -25.667
ValueofY is 10

Absoulse value ofx is 25.667

Cube Root ofy is L 154434690031884

Highest value among x and y is 1I)

Lowest value among x and y is -25 ..667

PO'IV"et is 658)948890000001

Square Root ofy is 3.1622776601683795


TPS Information Technology (Science) 3-56 Advanced JavaScript

. Date Object:
Date object is used to create date and time values. It is created using new keyword.
Method Description
getDateO Returns the day of the month (from 1-31)
getDayO Returns the day of the week (from 0-6)
getFullYearO Returns the year (four digits).
getHoursO Returns the hour (from 0-23).
getMinutesO Returns the minutes (from 0-59).
getMonthO Returns the month (from 0-11).
getSecondsO Returns the seconds (from 0-59).
getTimeO Returns the number of milliseconds since midnight jan I, 1970.
nowO Returns the number of milliseconds since midnightIan I, 1970.
setDateO Sets the day of the month of a date object.
setFullYearO Sets the full year of a date object.
setHoursO Sets the hours of a date object.
setMinutesO Set the minutes of a date object.
setMonthO Sets the month of a date object.
setSecondsO Sets the seconds of a date object.
setTimeO Sets a date to a specified number of milliseconds after Ibefore
Ian I, 1970.
~ Program to make use of various methods of date object.
-Coding:
<html>
<script type="textljavascript">
var d=new Datet):
document.wntet'xbrc-cbr» Date is "+d);
document.writef'xbrc-cbr» Day of the month is "+d.getDate());
document.write(,,<br><br> Day of the week is "+d.getDay());
document.write(,,<br><br> Year is "+d.getFullYear(»;
document.writet''cbrc-cbr» Month is "+d.getMonth());
document.writef''cbrc-cbr» Hours "+d.getHoursO);
document. write(" <br> <br> Minutes "s-d.getlvllnutesu):
document.write(" <br> <br> Seconds" +d.getSeconds());
TPS Information Technology (Science) 3-57 Advanced JavaScript

document.writel'xbro-cbr> Time in millseconds "+d.getTime());


</script> \

</html>
Output:
'" date,htmi

~" -); C

Date is Mon Apr 272020 14:19:12 GMT+0530 (India Standard Time)

Day of the month is 27

Day of the week is 1

Year is 2020

Month is 3 '
\
Hours 14

Minutes 19

Second. 12

Time in millseconds 1587977352499

Number Object:
It helps in working with numbers. Property and Methods of number object are:
Property Description
MIN_VALUE Returns the largest minimum value.
¥AX_VALUE Returns the largest maximum value.
NaN It represents 'Not a Number' value.
Method Description
isIntegerO It determines whether the given value is a Integer
parseFloatO It converts the given string into a floating point number.
parselntt) It converts the given string into a integer number.
isFixedO It returns the string that represents a number with exact-digits after
a decimal point.
-- ~ _ ~- -- ... --- ----'"-- .. -.-~--.~ ..~. ~ --- -

}> Program to make the use of Number property and methods.


Coding:
-chtml»
<script type="text/javascript">
var a,b;
TPS Information Technology (Science) 3-58 Advanced JavaScript

var x=Number.MAX_ VALUE;


var y-Number.Mfbl , VALUE;
a=25.36;
b=" 20.33 ";
document.writef''<brc-cbr> Convert data in to Integer "+parseInt(a));
document.writel'<br>cbr> Convert data in to Float "+parseFloat(b»;
document.writet'<brc-cbr> Value of X is "+x);
document.write("<br><br>Value of Y is"+y);
document.writef'<bre-cbrc-Is integer "+Number.isInteger(b»;
document.writef'<brc-xbrxls Not a Number "+Number.isNaN(b»;
-c/script»
</html>
Output:
x

Convert data in to Integer 25

Convert data in to Float 10.33

Value of X is L7976931348623157e+308

Value ofY is 5e~324

Is integer false

Is Not a Number false

Array Object:
An arrayis an object that can store a collection of items. Arrays are used' to store
multiple values in single variable. Array is a special variable which can hold more
than one values at a time. Property and Methods of array object are:
Property Description
Index The property represents the zero-based index of the match in the
string
Length Reflect number of elements in array. !
TPS Information Technology (Science) 3-59 Advanced JavaScript

Method Description
concat() Joins two or more arrays, and returns a copy of the joined arrays
copyWithinO Copies array elements within the array, to and from specied
.positions.
findt) Returns the value of the first element in an array that satisfies a test
in testing.
forEachO Calls a function for each array element.
indexOfO Search the array for an element and returns its position.
isArrayO Checks whether an object is an array.
popt) .Removes the last element ofan array, and returns that element.
pusht) Adds new elements to the end of an array, and returns the new
length.
reverser) Reverses the order of the elements in an array.
sortt) Sorts the elements of an.array.
_ .. _ .. -_ .. -- --- --- -- -- - - -

~ Program to make use of methods and property of Array Objects.


Coding: .
<html>
<script type='fext/javascript">
var color=["Red","Green","Blue","Orange","Pink"];
vat colorl=:["Black","white"];
document.write("<br><br> Original Array elements are "+color);
document.writef'<brs-cbrxLength of array is "s-cclor.Iength):
document.write("<br><br>Add both arrays "s-color.concatfcolor'l l):
document.write("<br><br>Adding elements to an array ")~
color.pushi'Yellow"):
.document.write("<br><br>");
document.write( color);
document.write("<br><br>Removing elements to an array");
color. popt):
document. writet'<br>cbr>" +color):
document.write(" <br> <br> Reversing array elements "+color.reverseO);
document.write(,,<br><br> Sort array elements "s-color.sortu):
document.write("<br><br>Check whether object is array or not
"+Array.isArray( color»;
TPS Information Technology (Science) 3-60 Advanced JavaScript

document. write(" <bre-cbrc-Check Positions of blue +color.indexOf("Blue"»; II

document.writet'<brc-cbrc-Copy elements at the end to beginning


"+color.copyWithin(O,2));
</script>
</html>
Output:
em File t E:!Xn%20SCl9&20.n-%202020-.21/ji31vascr'i...

Or!i:ginalArray' elements are Red.Green.Btue.Orange .•Pink

Le-ngt-h. of array 1.S. 5

Add 'both arrays: Re~Gr~i.Blue,.Or~ge~Pink,.~lac-k.~vhite

Adding edesraesrts. to an array

Red"Gl."een.Blue:-Orange,Pirik." Yeljow

Removmg e!ernents: to ru:~arilray

Red .•Green.Blue"Orange"Pink

Reveremg array ;e·lernentsPlnk"Ora.nge~Blue:-Green.,Red

Sort array elemesas Blue,Gr-een,Onmge,Pink,Red

Check ,,,-bether object is array or not- tree

Check Positions of blue 0

.Copy efemenrs at-the' end to be.ginningOrange.,Pink.Red'pWk,R...o:d

3.1 Introduction
1. Explain the features of JavaScript.
Ans.:
• JavaScript is light weight scripting language.
• No need of special software to run JavaScript Programs
• JavaScript is object oriented scripting language
• It can handle. date and time very effectively.
• It is case sensitive language.
2. Explain difference between Client Side and Server Side Scripting.
Ans.: Client Side Scripting:
(a) It is used at frontend which users can see from the browser.
(b) Client side scripting does not need any server interaction.
(c) Client Side scripting language involves languages such asHTML5, JavaScript etc.
(d) Client side scripting is used for validation purpose.
TPS Information Technology (Science) 3-61 Advanced JavaScript

Server Side Scripting:


(a) It is used at the backend, where the source code is not visible or hidden at the client
browser.
(b) When a server side script is processed it communicates to the server.
(c) Server side scripting language involves languages such as PHP, ASP.NET, Python
etc.
(d) Server side scripting is useful in customizing the web pages and implements the
dynamic changes in the web site.

3.2 Switch case and Looping Structures


3. Explain Switch case.
Ans ..:
[avafcript has decision control statement known as switch. The switch statement
test the value of given expression against the .list of case values and when. the match is
found a block of statement associated with that case is executed.
Syntax of switch case is:
switch( expression)

case x:
II code block
break;
case y:
II code block
break;
default:
II code block

4. Explain For loop with syntax.


Ans.:
The JavaScript for loop iterates the elements for the fixed number of times. It should
be used if number of iteration is known. The syntax of for loop is given below:
for (initialization; condition; increment)

code to be executed
TPS Information Technology (Science) 3-62 Advanced JavaScript

5. Explain while loop with syntax.


Ans.: The JavaScript ,while loop iterates the elements for the infinite number of times. It
should be used if number of iteration is not known. The syntax of while loop is given
below.
while (condition)

code to be executed

6. ExplainDo while loop with synta,x.


Ans. : The javascript do while loop iterates the elements for the infinite number of times
. like while loop. But, code is executed at least once whether condition is true or false. The
syntax of do while loop is given below.
do{
code to be executed;
} while (condition);
7. Explain Break and Continue statement in JavaScript.
Ans.:
1. Break statement: The break statement.isusedto jump out of a loop. It breaks the
loop and continues executing the code after the loop.
2. Continue statement: The continue statement "jumps over" one iteration in the
loop. It breaks iteration in the loop and continues executing the next iteration in the
loop.

3.3 Objects in JavaScript


8. Explain DOM (Document Object Model).
Ans.: Every web page resides inside a browser window which can be considered as an
object. A Document object represents the HTML document that is displayed in that
window. The Document object has various properties that refer to other objects which
allow access to and modification of document content. The way document content is
accessed and modified is called the Document Object Model, or DOM.
9. Explain Methods and Property of DOM.
Ans.:
Property Description
head Returns the <head> element of the document
Title Sets or returns title of the document.
URL Returns full URL of the HTML document.
body, img Returns <body>, <img> elements respectively.
TPS Information Technology (Science) ·3-63 Advanced JavaScript

Method Description
writet) Writes HTML expressions or JavaScript code to a document.
writelnO Same as write(), but adds a newline character after each
statement.
getElementByldO There are many ways of accessing form elements, of which the
easiest is by getElementByldO method. In which id property is
-used to find an element.
10. Explain alert, prompt and confirm methods of Window Object.
Ans. .
alertf) Displays the alert box containing message with ok button.
confirmf) Displays the confirm dialog box containing message with ok and cancel
button.
promptO Displays a dialog box to get input from the user.

3.4 JavaScript Events


11. Explain onblur, onsubmit, onload, onfocus event handlers in JavaScript.
Ans.:
Event handler Description
Onblur It occurs when user leaves field or losses focus of an element.
Onfocus It occurs when an element gets focus.
Onsubmit It occurs when user clicks submit button.
onload L I~~c,=-u~s
when p~ge/image has been loaded.
--- ---.-.~-- ----

3.5 JavaScript built-in Objects


12. Explain methods of String object (any 5) in JavaScript.
Ans.:
Method Description
charAtO Returns the character at the specified position (in Number).
indexOfO Returns the index of the first occurrence of specified character in
given string, or -1 if it never occurs, so with that index you can
determine if the string contains the specified character.
substring() .' Returns the characters you specified: (7,14) returns all characters
between the 7th and the 14th.
trimO The trimO method removes whitespace from both sides of a string
toLowerCaseO Converts a string to lower case
----- -- - ---- ~
TPS Information Technology (Science) 3-64 Advanced JavaScript

13. Explain methods of Math object (any 5) in JavaScript.


Ans.:
Method Description
,

abs(x) Returns the absolute value of a number.


cbrt(x) Returns the cube root of a number.
ceil(x) Returns the next integer greater than or equal to a given number
(rounding up).
max(x, y, ...) Returns the highest-valued number in a list of numbers.
pow(x,y) Returns the base to the exponent power, that is, xy.
14. Explain methods of Date object (any 5) in [avabcript.
Ans. :
Method Description
getDateO Returns the day of the month (from 1.,31)
getSecondsO Returns the seconds (from 0-59).
setMinutesO Set the minutes of a date object.
setMonthO Sets the month of a date object.
setTimeO Sets a date to a specified number of milliseconds after/before
[an 1, 1970.
15. Explain methods of Number object (any 4) in JavaScript.
Ans.:
Method Description
islntegerO It determines whether the given value is a Integer
parseFloatO It converts the given string into a floating point number.
parseInt() It converts the given string into a integer number.
isFixedO It returns the string that represents a number with exact digits after a
,
decimal point.
-
- - -

16. Explain methods of Array object (any 5) in JavaScript.


Ans. : .
Method Description ,

concan) Joins two-or more arrays, and returns a copy of the joined arrays
indexOfO Search the array for an element and returns its position.
popO ,
Removes the last element of an array, and returns that element.
pusht) Adds new elements to the end of an array, and returns the new length.

__
reverset)
.. ~_.__ ____ -I
Reverses the order of the elements in an array,
_____ . __ , ___ _.. _
TPS Information Technology (Science) 3-65 Advanced JavaScript

1. Program to print Addition, Subtraction, Multiplication and Division of two


numbers. Accept numbers from user.
Coding:
<html>
<script type="text/javascript">
var a,b,res;
a=parseInt(prompt("Enter First Number"»;
b=parseInt(prompt("Enter Second Number"»;
res=a+b:
document.write("<br><br>Addition is "+res);
res=a..;b;
document.write(,,<br><br>Substraction is "+res);
res=afb:
document.write("<br><br>Multiplication is "+res);
resea/b:
document.write("<br><br>Division is "+res);
</script>
</html>

2. Program to print Addition, Subtraction, Multiplication and Division of two


numbers using switch case. Accept numbers from user.
Coding:
<html>
<body>
<form name="frml ''>
Enter First Number
<input type="text" namee'f l'c-cbro-cbr>
Enter Second Number
<input type="text" name="t2"><br><br>
Enter your choice between 1 -4
<input type="text" name="t3"><br><br>
<input type="button" name='b'l" value=Check'' onClick="resO">
< I form>
TPS Information Technology (Science) 3-66 Advanced JavaScript
</body>
<script type="text/javascript">
function rest)

var a,b,c,r;
a=parseInt(frm1.t1.value);
b=parseInt(frm1.t2.value);
c=parseInt(frm1.t3.value);
switch(c)

case 1:
r=a+b;
alert("Addition is "+r);
break;
case 2:
r=a-b;
alert("Substraction is "+r);
break;
case 3:
r=a*b;
alert("Multiplication is "+r);
.break;
case 4:
r=a/b;
alert("Division is "+r);
break;
default:
alert("Invalid choice ");

</script>
</html>·
TPS Information Technology (Science) 3-67 Advanced JavaScript

3. Program to display numbers from 1 to 50.


Coding:
<html>
<script type="text/javascript">
var i;
document.writet''<brc-Numbers from 1-50 are <br>");
for(i=I;i<=50;i++ )
{
document.write(,,\ t"+i);

</script>
</html>
4. Program to display Evennumbers from 25to 50.
Coding:
<html>
<script type='text/javascript">
var i;
document.writef<brc-Even Numbers from 25-50 are <br>");
,.,
for(i=26·i<=50·i=i+2)

docnment.writef'Yt'x-i):

</script>
</html>
5. Program to print Multiplication table of the entered number:
Coding:
<html>
<script type="text/javascript">
var n,i,m;
n=prompt("Enter a Number");
document;write("<br>Multiplication Table is <br>"):
for(i=I;i<=lO;i++ )
TPS Information Technology (Science) 3~68 Advanced JavaScript

m=rrti:
document.write(n+" X H+i+" = "+m+"<br><br>n);

</script>
</html>
6. Programto print factorial of a number, accept number from the user.
Coding:
<html>
<script type='fext/jevascript''>
var n.i.f=I:
n=promptr'Enter a Number"):
for(i=n;i>=l;i-- )

f=f*i;
J
document.writef'<brc-Factorial is "+f);
</script>
</htm1>

Fill in the blanks


1. script resides on server computer.
Ails. : Server Side
2. ____ statement is-used to jump out of loop.
Ans.:Break
3. defines logical structure of document.
Ans. : DOM (Document Object Model)
4. property of window object returns Boolean value in- dictating whether
window is closed or not.
Ans, : closed
5. ____ event occurs when an element looses its focus.
Ans. : onblur
TPS Information Technology (Science) 3-69 Advanced JavaScript

State whether given statement is true or false.


1. JavaScript is case sensitive language.
Ans.:True
2. Math.ceilf) function is used to return the nearest integer less than or equal to given
number.
Ans.: False
3. MAX_VALUEproperty of number object returns smallest possible value.
Ans.: False
4. getDayO method of Date object returns month in number.
Ans. : False
5. onKeydown event occurs when user moves mouse pointer.
Ans.: False

Multiple choice questions. Select one correct answer.


1. JavaScript is language.
(a) Compiled . (b) Interpreted
(c) Both a andb (d) None of the above
Ans. : (c)
2. . Select correct method name of String object .
(a) charAtO (b) characterAtO
(c) valueAtO (d) lengthAtO
Ans.: (a)
·3. method displays message box with Ok and Cancel button ..
(a) Confirmt) (b) Alertt)
(c) both a and b (d) None of these
Ans. : (a)
4. We can declare all types of variables using keyword _
(a) var (b) dim (c) variable (d) declare
Ans.: (a)
5. .Traceoutput of following JavaScript code.
var str="Information Technology";_
document.write(str.lastIndexOf("o");
(a) 18 (b) 19 (c) 20 (d) 21
Ans.: (c)
TPS Information Technology (Science) 3-70 Advanced JavaScript

.Multiple choice questiens. Selecttwo'cofl'e~tanswer.


1. Valid two methods of Date object are and -'-
(a) set'I'imet) (b) getValidTimeO
(c) get'I'imef) (d) setValidTimeO
. Ans.: (a, c)
. 2. Properties of document object are and ~ _
(a), URL (b) title (c) name (d) status
Ans.: (a, b)
t
3. _______ and are event / event handler used with text object in
JavaScript.
(a) onlslur (b) onMove (c) onFocus (d) onAction
Ans, :(a,~L

Multipleehoiee questions. Select three eerrect answers.


1. Select three correct methods of window object _
(a) write() (b) alert() (c) writelnO (d) closet)
(e) operu) (f) charAtf)
Ans. : (b, d, e)
2. JavaScriptfeatures are . and .
(a) supports event based facilities (b). is platform dependent language
. (c) case insensitive scripting language (d) provide inbuilt objects
(e) can handle date and time effectively (f) requires special software to run
Ans. : (b, c, e)
3. Inbuilt objects in JavaScript are and '
(a) Time (b)' Date (c) Inheritance
(d) Array (e) Number (f) function
Ans. : (b, d, e)

Explain the following.


1.' What are similarities and differences between client side scripting and server side
scripting.
Ans.: Refer answer the followingQ. 2.3.1.
2. Briefly explain features of JavaScript.
Ans. : Refer answer the following Q. 1.3.1.
3. Explain switch case conditional statement in JavaScript with example.
Ans. : Refer answer the following Q. 1.3.2.
TPS Iriformatien-Teehnology (Science) 3-71 Advanced JavaScript

Write event driven JavaScript program for the following.


1. Display Addition, substraction, multiplication, division of two numbers, which
were accepted from user.
Coding.:
<htm1>
<script type="text/javascript">
vara,b,res;
a=parselnt(prompt("Enter First Number"»;
b=parseInt(prompt("Enter Second Number"»;
res=a+b:
- document.wri,te("<br'><br>Addition is "+res);
rese.a-b:
document.write("<br><br>Substraction is "+res);
res=a*b;
document.write("<br><br>Multiplication is "+res);
resea/b:
document.write("<br><br>Division is "+res);
</script>
</html>
2. Display number sequence from 100 to 150 in following fonnat.
(100 101102 150>
Coding:
<html>
I <script type="text/javascript">
var i;
document.writef'<brc-Numbers from 100-150 are <br>"):
for(i=100;i<=150;i++ )
{
document.write("\ t"+i);

</script>
</html>
3. Find and display factorial of given number.
Coding:
<html>
<script type="text/javascript">
var n=4,i,f=1;
TPS Information Technology (Science) 3-72 Advanced JavaScript

,for(i=n;i>=l;i--)
{
f=f>ti;
}
document.writef'<brc-Factorial of 4 is n+f);
</script>
</html>
4. Accept any string from user and count and display number of vowels occurs in it.
Coding:
<html>
<script type=tltext/javascripttl>
var n,i,ch,cnt=O;
n=prompt(tlEnter a String"):
for(i=O;i <n.length;i ++ )
{
ch=n.charAt(i);
if(ch=='a' I I ch=='A' I Ich=='e' I I ch=='E' I Ich=='i' I I ch=='i' I I

ch=='o' I I ch=='O' I I ch=='u' I I ch=='U')


{
cntecnt+ 1;.
}
}
document.writef'Number od vowels in string are "s-ent):
</script>
<7html>

Match the following -~~

A B
1. cellO (a) Writes HTML expression or JavaScript code to a document.
2. floorO (b) Sets focus to current window.
3: writeO (c) Removes white ~paees from both sides of string.
4; .... focusf) (d) Returns next integer greater than or equal to given number.
5. trimO (e) Returns the next integer less than or equal to given number,
Ans.: 1. - d, 2. - e, 3. - a, 4. - b, . 5. ~c

DDD

You might also like