Q 1. See the given code of JavaScript and choose the correct output from the following:
var string1 = “40”;
varvalueinit=50;
alert( string1 +intvalue);
A. 90
B. 4050
C. 4090
D. Exception
Show Answer
Answer:-B. 4050Explanation
In JavaScript, the alert method does the typecasting and converts the value of the variable “valueinit” to a string after that it concatenates both of the strings and displayed them on the screen. So, here the correct output would be 4050.Q 2. In JavaScript, what will be used for calling the function definition expression:
A. Function prototype
B. Function literal
C. Function calling
D. Function declaration
Show Answer
Answer:-B. Function literalExplanation
A function definition expression is a kind of “function literal’ just like as the object initializer is a kind of “object literal”. The function definition expression (or we can say a function literal) consists of the keyword Function, followed by the set of identifiers(or parameters names) that are separated by commas inside the parenthesis, and a small block of JavaScript code(which we normally called function body/definition) enclosed in the curly braces.Q 3. Which of the following one is the property of the primary expression:
A. Contains only keywords
B. basic expressions containing all necessary functions
C. contains variable references alone
D. stand-alone expressions
Show Answer
Answer:-D. stand-alone expressionsExplanation
In JavaScript, the primary expressions also called simplest expressions are those standalone expressions, which do not include any of the simpler expressions. The variable, constant or literal values and certain language keywords are the basic examples of the primary expressions.Q 4. Consider the following snippet of JavaScript code:
var text =”testing: 1, 2, 3″;// Sample text
var pattern =/\d+/g// Matches all instances of one or more digits
Which one of the following statement is most suitable to check if the pattern matches with the sting “text”.
A. test(text)
B. equals(pattern)
C. test(pattern)
D. text==pattern
Show Answer
Answer:-D. text==patternExplanation
The given pattern is applied on the string “text” enclosed in the parenthesis.Q 5. Which one of the following is used for the calling a function or a method in the JavaScript:
A. Property Access Expression
B. Functional expression
C. Invocation expression
D. Primary expression
Show Answer
Answer:-C. Invocation expressionExplanation
The invocation expression is one of the JavaScript’s syntax which is used for making a function call or calling a method. It always starts with the function expression which identifies the certain function to be called or executed.Q 6. The “new Point(3,2)”, is a kind of _______ expression
A. Constructor Calling Expression
B. Primary Expression
C. Invocation Expression
D. Object Creation Expression
Show Answer
Answer:-D. Object Creation ExpressionExplanation
The object creation expression creates a new object and also invokes a method called constructor in order to initialize the properties of that object. The object creation expressions are just like the invocation expressions except that they prefixed with a keyword commonly known as New.Q 7. Which one of the following operator is used to check weather a specific property exists or not:
A. Exists
B. exist
C. within
D. in
Show Answer
Answer:-D. inExplanation
In JavaScript, the “in” operator is used to check if a specific property exists. The “in” operator is commonly used in looping statements to traverse array and objects as well.Q 8.Which one of the following is an ternary operator:
A. ?
B. :
C. –
D. +
Show Answer
Answer:-A. ?Explanation
In JavaScript, only one ternary operator is supported, known as the conditional operator, which combines three different expressions into one expression. However, the conditional operator can also be used in place of the “if else” statements as well.Q 9. “An expression that can legally appear on the left side of an assignment expression.” is a well known explanation for variables, properties of objects, and elements of arrays. They are called_____.
A. Properties
B. Prototypes
C. Definition
D. Lvalue
Show Answer
Answer:-D. LvalueExplanation
The term “lvalue” is one of the historical terms which states that “an Expression that can appear legally on the left-side of the Assignment Expression”. The properties of objects, elements, and variables are lvalues in JavaScript.Q 10. Which of the following is the correct output for the following JavaScript code:
function display1(option)
{
return(option ? “true” : “false”);
}
bool ans=true;
console.log(display1(ans));
A. False
B. True
C. Runtime error
D. Compilation error
Show Answer
Answer:-B. TrueExplanation
In the following JavaScript code, the “?” is being used which is also known as ternary operator”. Here it is used to choose one option as a choice among the given two options. However, it is often used to write shorter and simple code because it can be used in the place of “if else” statements.Q 11. Which one of the following is correct output for the following given JavaScript code:
var obj=
{
length:20,
height:35,
}
if(‘breadth’ in obj === false)
{
obj.breadth = 12;
}
console.log(obj.breadth);
A.Error
B. Undefined
C. 12
D. 20
Show Answer
Answer:-C. 12Explanation
In the above given JavaScript code, the “in” operator is used which checks (or performs search) for the specific property. If the certain property is found it returns true otherwise it returns false.Q 12. Which one of the following is correct output for the following given JavaScript code:
functionheight()
{
var height=123.56;
var type =(height>=190)?”Taller”:”Little short”;
return type;
}
A. 123.56
B. Taller
C. 190
D. Little shorter
Show Answer
Answer:-B. TallerExplanation
In the above given code, the ternary operator is used that works on the 3 operands. The statement in the following code, initialize the type variable with value “little shorter” that is returned through the function.Q 13. Which one of the following is correct output for the following given JavaScript code:
string X= “Good”;
string Y=”Evening”;
alert(X+Y);
A. Good
B. Evening
C. GooodEvening
D. undefined
Show Answer
Answer:-C. GooodEveningExplanation
The alert method is commonly used for Displaying the value(or message) passed as argument in the “dialogbox” in the web-browser. Here, the alert method concatenates both given strings and prints as a single string in the form of output.Q 14. Which one of the following is correct output for the following given JavaScript code:
functionoutputfun(object)
{
var place=object ?object.place: “Italy”;
return “clean:”+ place;
}
console.log(outputfun({place:India}));
A. Error
B. clean:Italy
C. clean:India
D. undefined
Show Answer
Answer:-C. clean:IndiaExplanation
In the following given code, the “?” ternary operator is used for comparing the values and place is determined (or initialized) according to the true condition that whether it returns true (1) or false (0).Q 15. Which one of the following is correct output for the following given JavaScript code:
<p id=”demo”></p>
<script>
functionourFunction()
{
document.getElementById(“demo”).innerHTML=Math.abs(-7.25);
}
</script>
A. 7
B -7.25
C. 25
D. -7
Show Answer
Answer:-C. 25Explanation
In the following code, the method “abs ()” is used which returns absolute numbers as output hence the correct option is c. In JavaScript, the “abs ()” method is one of the methods stored in the library called Math’s.Q 16. Which one of the following is correct output for the following given JavaScript code:
<p id=”demo”></p>
<script>
function Function1()
{
document.getElementById(“demo”).innerHTML=Math.cbrt(792);
}
</script>
A. 9
B. 81
C. 972
D. Error
Show Answer
Answer:-C. 972Explanation
Here the code above uses the “cbrt ()” method, which returns the cube root of the number passed in parentheses as an argument. The “cbrt()” method is one of the several methods that are found in the library called math’s available in the JavaScript.Q 17. Which one of the following is correct output for the following given JavaScript code
<p id=”demo”></p>
<script>
functionmyFunction()
{
document.getElementById(“demo”).innerHTML=Math.acos(0.5);
}
</script>
A. 01
B. 4
C. 00
D. 047
Show Answer
Answer:-D. 047Explanation
The method “acos()” used in the above code returns the arccosine of any number passed in it as an argument. The returned value lies in between 0 and PI radians if the passed value exceeds the limit from -1 to 1, the “acos()” methods returns the NaN(also known as Not a Number).Q 18. What we will get if we compare the “one” with “8” using the less than operator (“one”<8)?
A. False
B. True
C. NaN
D. Undefined
Show Answer
Answer:-A. FalseQ 19. Which one of the following is known as the Equality operator, which is used to check whether the two values are equal or not:
A. =
B. ===
C. ==
D. &&
Show Answer
Answer:-C. ==Explanation
The “==” called the equality operators, it returns true if both the value are equal otherwise it returns false.Q 20. Which one of the following operator returns false if both values are equal?
A. !
B. !==
C. !=
D. All of the above
Show Answer
Answer:-C. !=Explanation
The “!=” operators returns false if both the given values are equal.Q 21. In a case, where the value of the operator is NULL , the typeof returned by the unary operator is___.
A. undefined
B. string
C. boolean
D. object
Leave a Reply