NEW
Font size
WorksheetsJavaScript Assessment-2
Total questions: 20
Worksheet time: 10mins
Arrays are written in JavaScript using which of the following?
round brackets ()
curly brackets {}
double quotes ""
square brackets []
Which of the following syntax for the function definition is appropriate?
return_type function function_name(parameter1, parameter2, ...) { /*Function's body*/ }
function function_name(parameter1, parameter2, ...) { /*Function's body*/ }
return_type function_name(parameter1, parameter2, ...) { /*Function's body*/ }
function function_name(parameter1, parameter2, ...) as return_type { /*Function's body*/ }
What will be the output of the following JavaScript code?
<script>
function addition(a, b)
{ return a+b; }
document.getElementById("test").innerHTML = addition;
</script>
SyntaxError
ValueError
0
function addition(a, b) { return a+b; }
Which is the correct syntax to access an object property in JavaScript?
objectName:propertyName
objectName.propertyName
objectName["propertyName"]
Both B. and C.
In JavaScript, which attribute is utilised to determine a string's length?
strlen
len
length
Length
Which is the correct JavaScript statement to define string as object?
var s = new String("Let us learn JS!");
var s = String("Let us learn JS!");
var s = "Let us learn JS!"
All of the above
Which is/are the valid JavaScript method(s) to extract string parts?
slice(start, end)
substring(start, end)
substr(start, length)
All of the above
How can a number be converted into a string using JavaScript?
parseInteger()
intToString()
toString()
All of the above
What will be the output of the following JavaScript code?
<script>
const myArray = ['h', 'e', 'l', 'l', 'o'];
document.write(myArray[1]);
document.write(myArray[2]);
</script>
he
el
ValueError
TypeError
Which JavaScript method is used to call a function (a callback function) once for each array element?
for()
traverse()
forEach()
None of these
What will be the output of the following JavaScript code?
<script>
const arr = [1, 2, 3];
let result = 0;
arr.forEach(myFunction);
document.write("Result: " , result)
function myFunction(value, index, array) { result += value; }
</script>
Result: 6
Result: 123
Result: 1,2,3
ValueError
Which JavaScript method is used to create a new array with array elements that passes a test?
forEach()
map()
forMap()
filter()
What will be the output of the following code snippet?
<script>
var a = "Javascript";
var result = a.substring(2, 5);
document.write(result);
</script>
ava
vas
avas
vasc
What will be the output of the following code snippet?
<script>
var x=01;
var y=99;
var res=eval("x+y");
document.write(res);
</script>
100
0199
x+y
None of these
What will be the output for the following code snippet?
<p id="example"></p>
<script>
function Func() {
document.getElementById("example").innerHTML=Math.sqrt(81);
}
</script>
9
81
Error
None of these
What will be the output of the following code snippet?
var a = 1;
var b = 0;
while (a <= 3) {
a++;
b += a * 2;
print(b);
}
4 10 18
1 2 3
1 4 7
None of these
Which function is used to serialize an object into a JSON string in Javascript?
parse()
stringify()
convert()
None of the above
What will be the output of the following code snippet?
let sum = 0;
const a = [1, 2, 3];
a.forEach(getSum);
print(sum);
function getSum(ele) { sum += ele; }
6
1
2
None of these
How to stop an interval timer in Javascript?
clearTimer
clearInterval
intervalOver
None of the above
What is the output of the following code snippet?
print(NaN === NaN);
true
false
undefined
Error
