WorksheetsJavaScript - Practice 10
Total questions: 20
Worksheet time: 11mins
const body = document.body;
In JavaScript, what does it do?
Creates a constant which reference to the body element
Creates a duplication of the body element, and every change does not affect the body element
const body = document.body;
What is the type of body?
(a)
How to get all elements by their tag name in JavaScript?
document.getElementsByTagName();
document.getElementsByTag();
document.getElementsByTabName();
document.getElementByTagName();
How to get all elements by their class name in JavaScript?
document.getElementsByClassName();
document.getElementsByClass();
document.getElementsByClassNames();
document.getElementByClassName();
document.querySelector('#bats');
What does it do in JavaScript?
It uses CSS notation to find the first element with id 'bats'
It uses CSS notation to find the element with class 'bats'
It returns a node list of all the elements with id 'bats'
It find the elements that matches a CSS selector '#bats'
Are document.querySelectorAll('.bats') as same as document.getElementsByClassName('bats')?
Yes
No
In Document Object Model (DOM), all the properties, methods and events that are available to a web developer for manipulating and creating web pages are organised into:
Classes
Objects
Modules
Variables
DOM represents a webpage in what way?
Dynamic structure
Recursive structure
Tree-like structure
Hash table structure
Which of the following is an appropriate event handler for input text?
onclick
onchange
onkeyup
onblur
Which of the following is an appropriate event handler when the user clicks on an element?
onclick
onchange
onkeyup
onblur
Identify the correct code in order to fetch the value entered in username text field?
document.register.name.value
document.getElementById ("name").value
document.getElementByName ("name").value
None of the these
How to add event handler that would be invoked when the document's body is clicked?
document.onclick = function (){
// do something
};
document.body.addEventListener('click', doSomethingFunction);
document.click = function (){
// do something
};
document.body.addEventListener('onclick', doSomethingFunction);
document.body.onclick = function (){
// do something
};
document.body.addEventListener('click', () => alert('You clicked!'));
Which type of the handler function is in above JavaScript code?
Arrow function
Lambda function
Parentheses function
Short function
What is the difference between keydown and keypress event in JavaScript?
keydown event occurs when a key is pressed
keypress event occurs after keydown event and only occurs for keys that produce character input
keydown event occurs when a key released
keypress event occurs when a key was pushed down
keydown and keyup events occur when a any key is pressed
Can you remove an event in JavaScript?
Yes
No
Which of the method following are used to navigate around the DOM tree?
parentNode()
nextSibling()
nextDaughter()
childrenNodes()
previousChild()
Which of the following is the container for input elements?
Form
Page
Canvas
Input
How many primitive data types in JavaScript?
6
7
5
4
What is callback function?
A callback is a function that is provided as an (a) to another function.
What does JSON stand for?
JavaScript Object Notation
Java Object Notation
JavaScript Object Normalization
JavaScript Object-Oriented Notation
