JavaScript Course | Practice Quiz-1

  • Last Updated : 22 Sep, 2021


Question 1
Inside which HTML element do we put the JavaScript?
A
<javascript>
B
<js>
C
<src>
D
<script>
JavaScript Course Quiz 1    
Discuss it


Question 1 Explanation: 
The <script> tag is used to contain javascript code.
Question 2
Where is the correct place to insert a JavaScript?
A
Both the head section and the body section are correct
B
The head section
C
The body section
D
None of the above
JavaScript Course Quiz 1    
Discuss it


Question 2 Explanation: 
We can place the <script> tag inside the head tag or the body tag, both the techniques are correct.
Question 3
Is it necessary for the external script file to contain a <script> tag?
A
Yes
B
No
C
Depends on the type of include
D
None of the above
JavaScript Course Quiz 1    
Discuss it


Question 3 Explanation: 
No, it is not at all necessary to place a <script> tag inside the external javascript code, as your editor already knows it is a javascript code as you have saved the file with .js extension.
Question 4
What is the correct syntax for referring to an external script called 'gfg.js'?
A
<script name="gfg.js">
B
<script href="gfg.js">
C
<script src="gfg.js">
D
None of these
JavaScript Course Quiz 1    
Discuss it


Question 4 Explanation: 
The 'src' attribute is the one which is used to link the javascript file to the HTML document.
Question 5
How many ways are there with which we can declare a variable in javascript?
A
Only one
B
Three
C
Infinitely many
D
None of the above
JavaScript Course Quiz 1    
Discuss it


Question 5 Explanation: 
Before ES6 we had only one way of declaring variables: using var. After ES6 we have two more ways, let and const.
Question 6
Is a variable named 'apple' same as 'Apple' in javascript?
A
Yes
B
No
C
Only when we use 'strict'
D
None of the above
JavaScript Course Quiz 1    
Discuss it


Question 6 Explanation: 
Javascript is case sensitive.
Question 7
Which of the following variable names are correct according to javascript? (Multiple Choices may be correct)
A
let 1name;
B
let #name;
C
let _name;
D
let $_name;
JavaScript Course Quiz 1    
Discuss it


Question 7 Explanation: 
Both the options C and D are correct. We can start the name of the variable with $ sign and an _(underscore).
Question 8

What will be the output of the following code?

< script >

document.write( typeof( '1' + 2) );

</ script >

A

'boolean'
 

B

'string'
 

C

'number'
 

D

None of the above
 

JavaScript Course Quiz 1    
Discuss it


Question 8 Explanation: 

The + operator will perform concatenation if either of the variables is a string.
 

Question 9

What will be the output of the following code?

< script>

let ans = 6 / "3";

document.write ( typeof ans );

< /script>

A

None of the above
 

B

'number'
 

C

'integer'
 

D

'string'
 

JavaScript Course Quiz 1    
Discuss it


Question 9 Explanation: 

A number, when divided by a string, will always result in a number.
 

Question 10
What is the correct JavaScript syntax to change the content of the HTML element below?
<p id="demo">May the code be with you.</p>
A
document.getElementById("demo").innerHTML = "Hola!";
B
document.getElement("p").innerHTML = "Hola!";
C
#demo.innerHTML = "Hola!";
D
document.getElementByName("p").innerHTML = "Hola!";
JavaScript Course Quiz 1    
Discuss it


Question 10 Explanation: 
The getElementById() method of DOM(Document) will return the element that has the ID attribute with the specified value declared in the braces. After getting the element we can change its HTML by using the innerHTML function of the Javascript.
There are 77 questions to complete.
My Personal Notes arrow_drop_up