β˜‘ MCQ PRACTICE

Web Technologies Unit 5

Practice objective questions for quick revision and examination preparation. Try answering each question before revealing the answer.

πŸ“š Web Technologies
πŸ“– Unit 5
🎯 MCQs

Web Technologies - JavaScript

1

What is the HTML tag under which one can write the JavaScript code?

A<javascript>
B<scripted>
C<script>
D<js>
Correct Answer<script>
2

Choose the correct JavaScript syntax to change the content of the following HTML code.
<p id="msg">Welcome</p>

Adocument.getElement("msg").innerHTML="Welcome to JavaScript";
Bdocument.getElementById("msg").innerHTML="Welcome to JavaScript";
Cdocument.getElementById("msg").innerHTML=Welcome to JavaScript;
Ddocument.getId("msg").innerHTML="Welcome to JavaScript";
Correct Answer document.getElementById("msg").innerHTML="Welcome to JavaScript";
3

Which of the following is the correct syntax to display "Welcome" in an alert box using JavaScript?

Aalertbox("Welcome");
Bmsg("Welcome");
Cmsgbox("Welcome");
Dalert("Welcome");
Correct Answeralert("Welcome");
4

What is the correct syntax for referring to an external script called "sample.js"?

A<script src="sample.js">
B<script href="sample.js">
C<script ref="sample.js">
D<script name="sample.js">
Correct Answer<script src="sample.js">
5

Predict the output of the following JavaScript code.

<script type="text/javascript">
a = 8 + "8";
document.write(a);
</script>
A16
BCompilation Error
C88
DRun Time Error
Correct Answer 88
6

Predict the output of the following JavaScript code.

<script type="text/javascript">
var a="WebTechnology";
var x=a.lastIndexOf("e");
document.write(x);
</script>
A1
B5
C4
DError
Correct Answer4
7

Predict the output of the following JavaScript code.

<script type="text/javascript" language="javascript">
var a = "WebTechnology";
var result = a.substring(3,4);
document.write(result);
</script>
AbTec
BTech
CTe
DbT
Correct AnswerTe
8

Predict the output of the following JavaScript code.

<script type="text/javascript" language="javascript">
var x=5;
var y=6;
var res=eval("x*y");
document.write(res);
</script>
A"30"
B30
C5*6
D"5*6"
Correct Answer30
9

What is the correct syntax for adding comments in JavaScript?

A<!–This is a comment–>
B//This is a comment
C–This is a comment
D**This is a comment**
Correct Answer//This is a comment
10

How to initialize an array in JavaScript?

Avar Items = "Item1", "Item2", "Item3"
Bvar Items = (1:Item1, 2:Item2, 3:Item3)
Cvar Items = (1=Item1, 2=Item2, 3=Item3)
Dvar Items = ["Item1", "Item2", "Item3"]
Correct Answervar Items = ["Item1", "Item2", "Item3"]
11

What will be the command to print the number of characters in the string "JavaScript"?

Adocument.write("JavaScript".len);
Bdocument.write(sizeof("JavaScript"));
Cdocument.write("JavaScript".length);
Ddocument.write(lenof("JavaScript"));
Correct Answerdocument.write("JavaScript".length);
12

JavaScript is a ________ Side Scripting Language.

AServer
BISP
CBrowser
DNone of the above
Correct AnswerBrowser
13

Predict the output on the console for the following JavaScript code.

<script>
function display() {
    if(true) {
        var a = 5;
    }
    document.write(a);
}
display();
</script>
ACompilation Error
B5
CNothing will be printed as output
DRuntime error
Correct Answer5
14

How do you round the number 7.25, to the nearest integer?

Around(7.25)
BMath.round(7.25)
Cmath.round(7.25)
Drnd(7.25)
Correct AnswerMath.round(7.25)
15

How do you find the number with the highest value of x and y?

AMath.ceil(x,y)
BMath.top(x,y)
Cceil(x,y)
DMath.max(x,y)
Correct AnswerMath.max(x,y)
16

Which event occurs when the user clicks on an HTML element?

Aonchange
Bonclick
Consubmit
Donload
Correct Answeronclick
17

How to write an IF statement for executing some code if "i" is NOT equal to 5?

Aif(i<>5)
Bif i!=5 then
Cif(i!=5)
Dif i<>5
Correct Answerif(i!=5)
18

Integer Variable is declared using following syntax in JavaScript.

Aint num;
Binteger num;
Cvar num;
Dnum
Correct Answervar num;
19

Which of the following can be used to select HTML elements based on the value of their name attributes?

AgetElementByName()
BgetElementsByName()
CgetElementsName()
DgetElementName()
Correct AnswergetElementsByName()
20

Which of the following is correct about features of JavaScript?

AJavaScript is complementary to and integrated with HTML
BJavaScript is open and cross-platform.
CBoth of the above.
DAll of the above
Correct AnswerBoth of the above.
← Back to All MCQs