Correct Answer: Orange && Worng Answer: Red
1. What will be the output of the following JavaScript code?
Int a = 1;
if (a > 10) {
document.write(10);
} else {
document.write(a);
}
View Answer
Explanation: The if else statement is a part of the javascript conditioning statements. The line of code inside the “if” statement is executed if the value passed to “if” is 1.
2. What kind of expression is “new Point(2,3)”?
View Answer
Explanation: An object creation expression creates a new object and invokes a function (called a constructor) to initialize the properties of that object. Object creation expressions are like invocation expressions except that they are prefixed with the keyword new.
3. What will be the equivalent output of the following JavaScript code snippet?
x = ~-y;
w = x = y = z;
q = a?b:c?d:e?f:g;
View Answer
Explanation: Brackets have higher precedence than any other operator. The placement of brackets results in the same result as without putting any bracket.
4. What will be the output of the following JavaScript code?
const obj = {prop: 12};
Object.preventExtensions(obj);
console.log( Object.isExtensible(obj));
View Answer
Explanation: The Object.preventExtensions() only prevents the addition of new properties from ever being added to an object. This change is a permanent that means once an object has been made non-extensible, it cannot be made extensible again.
5. What happens in the following javaScript code snippet?
var count = 0;
while (count < 10)
{
console.log(count);
count++;
}
View Answer
Explanation: Console.log is a predefined function in JavaScript which takes the value as an argument of its function.console.log prints this value in the argument in the console at the time of execution of the code.
6. What will be the output of the following JavaScript code?
function compare() {
int a = 1;
char b = 1;
if(a.tostring() === b) return true;
else return false;
}
View Answer
Explanation: A non string (integer) can be converted to string using .tostring() function. A strict comparison is only true if the operands are of the same type and the contents match. Hence the following code snippet would result into true output.
7. What will be the output of the following JavaScript code?
int a = 1;
if(a != null) return 1;
else return 0;
View Answer
Explanation: != is the not equal to operator. It gives a value of 1 if the two values which are compared are not equal and give 0 if the two values are equal.
8. What will be the output of the following JavaScript code?
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = Math.abs(-7.25);
}
</script>
View Answer
Explanation: The abs() method returns the absolute value of a number. The method is find in the math library of Javascript.
9. What will be the output of the following JavaScript code?
int a=0;
for(a;a<5;a++);
console.log(a);
View Answer
Explanation: The value of a will increase until it will become equal to 5 after that the cursor will come out the loop. There are no statements for the for loop therefore only the value of a will increase. Hence the output will be five.
10. What will be the output of the following JavaScript code?
var a1 = [,,,];
var a2 = new Array(3);
0 in a1
0 in a2
View Answer
Explanation: Array a1 is defined with null values. Therefore we can access the indexes 0, 1 and 2. But array a2 is only defined not declared. Therefore we cannot access index 0.
Categories
C Programming MCQsC++ Programming MCQsJAVA MCQsVisual Basic MCQsData Structure MCQsSoftware Package MCQsComputer Organization and Architecture MCQsOperating System MCQsDigital Electronics MCQsDBMS MCQsSystem Analysis and Management Information System MCQsSystem Maintenance MCQsData Communication and Networking MCQsInternet & Web Technology MCQsSoftware Engineering MCQsManagement (Common) MCQsSystem Software MCQsComputer Graphics MCQsArtificial Intelligence & Expert System MCQsE-Commerce MCQsMultimedia MCQsPower Electronics MCQsTesting & Maintenance Electrical Machine MCQsAutomatic Control System MCQsAdvance Communication System MCQsDigital Electronics MCQs