31). What will be the output of the following JavaScript code?
var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );
[A]123246
[B]246
[C]123123
[D]Exception
Show Answer
Correct Answer: 123123
Notes:
Answer: c
Explanation: In JavaScript the alert function does the type casting and converts the integer value to string. After that it concatenates both the strings and shows the result as a concatenated string. Thus 123123 would be correct.
32). A function definition expression can be called as __________
var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );
[A]Function prototype
[B]Function literal
[C]Function calling
[D] Function declaration
Show Answer
Correct Answer: Function literal
Notes:
Answer: b
Explanation: A function definition expression is a “function literal” in the same way that an object initializer is an “object literal.” A Function definition expression typically consists of the keyword function followed by a comma-separated list of zero or more identifiers (the parameter names) in parentheses and a block of JavaScript code (the function body) in curly braces.
33). The property of a primary expression is ____________
var string1 = ”123”;
var intvalue = 123;
alert( string1 + intvalue );
[A]stand-alone expressions
[B]basic expressions containing all necessary functions
[C]contains variable references alone
[D]contains only keywords
Show Answer
Correct Answer: stand-alone expressions
Notes:
Answer: a
Explanation: The simplest expressions, known as primary expressions, are those that stand alone — they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain language keywords, and variable references.
34). Consider the following JavaScript statements.In order to check if the pattern matches with the string “text”, the statement is ____________
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
[A]text==pattern
[B]text.equals(pattern)
[C]text.test(pattern)
[D]pattern.test(text)
Show Answer
Correct Answer: pattern.test(text)
Notes:
Answer: d
Explanation: The given pattern is applied on the text given in the parenthesis.
35). The expression of calling (or executing) a function or method in JavaScript is called ________
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
[A]Primary expression
[B]Functional expression
[C]Invocation expression
[D]Property Access Expression
Show Answer
Correct Answer: Invocation expression
Notes:
Answer: c
Explanation: An invocation expression is JavaScript’s syntax for calling (or executing) a function or method). It starts with a function expression that identifies the function to be called.
36). What kind of expression is “new Point(2,3)”?
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
[A] Primary Expression
[B] Object Creation Expression
[C]Invocation Expression
[D]Constructor Calling Expression
Show Answer
Correct Answer: Object Creation Expression
Notes:
Answer: b
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.
37). Which of the operator is used to test if a particular property exists or not?
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
[A]in
[B]exist
[C]within
[D]exists
Show Answer
Correct Answer: in
Notes:
Answer: a
Explanation: The operator “in” tests whether a particular property exists or not. In operator is usually added in looping statements to traverse the array or the object.
38). Among the following, which one is a ternary operator?
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
Show Answer
Correct Answer: ?:
Notes:
Answer: d
Explanation: JavaScript supports one ternary operator, the conditional operator ?:, which combines three expressions into a single expression. If else case can be replaced by the conditional operator
39). “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 ___________
var text = "testing: 1, 2, 3"; // Sample text
var pattern = /\d+/g // Matches all instances of one or more digits
[A]Properties
[B]Prototypes
[C]Lvalue
[D]Definition
Show Answer
Correct Answer: Lvalue
Notes:
Answer: c
Explanation: lvalue is a historical term that means “an expression that can legally appear on the left side of an assignment expression.” In JavaScript, variables, properties of objects, and elements of arrays are lvalues.
40). 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;
[A]x = ~(-y); w = (x = (y = z)); q = a?b:(c?d:(e?f:g));
[B]x = a?b:(c?d:(e?f:g)); q = ~(-y); w = (x = (y = z));
[C]x = (x = (y = z));w = ~(-y); q = a?b:(c?d:(e?f:g));
[D]x = ~(-y); w = (x = (y = z)); q = (c?d:(e?f:g));
Show Answer
Correct Answer: x = ~(-y); w = (x = (y = z)); q = a?b:(c?d:(e?f:g));
Notes:
Answer: a
Explanation: Brackets have higher precedence than any other operator. The placement of brackets results in the same result as without putting any bracket.
41). What will be the output of the following JavaScript code?
function output(option)
{
return (option ? “yes” : “no”);
}
bool ans=true;
console.log(output(ans));
[A]Yes
[B]No
[C]Runtime error
[D]Compilation error
Show Answer
Correct Answer: Yes
Notes:
Answer: a
Explanation: “?” is called the ternary operator which is used for choosing one choice from the given two choices. It is used instead of if else statement and makes the code shorter.
42). What will be the output of the following JavaScript code?
var obj=
{
length:20,
height:35,
}
if (‘breadth' in obj === false)
{
obj.breadth = 12;
}
console.log(obj.breadth);
[A]20
[B]12
[C]undefined
[D]error
Show Answer
Correct Answer: 12
Notes:
Answer: b
Explanation: The “in” operator checks for the presence of a particular property in object. It returns true if the property is present and returns false if the property is not present.
43). What will be the output of the following JavaScript code?
function height()
{
var height = 123.56;
var type = (height>=190) ? "tall" : "short";
return type;
}
[A]123.56
[B]190
[C]tall
[D]short
Show Answer
Correct Answer: short
Notes:
Answer: d
Explanation: The ternery operator is used as a comparison operator which works on three operands. The statement in the above code initializes type variable with the value short which is returned through the function.
44). What will be the output of the following JavaScript code?
string a = ”hi”;
string b =”there”;
alert(a+b);
[A]hi
[B]there
[C]hithere
[D]undefined
Show Answer
Correct Answer: hithere
Notes:
Answer: c
Explanation: alert function is used to print the value passed as argument in a dialog box in a browser. The alert function adds both the string and prints the result as a combined string.
45). What will be the output of the following JavaScript code?
function output(object)
{
var place=object ? object.place : “Italy”;
return “clean:”+ place;
}
console.log(output({place:India}));
[A]clean:India
[B]clean:Italy
[C]error
[D]undefined
Show Answer
Correct Answer: clean:India
Notes:
Answer: a
Explanation: ”?” operator is used to compare the values and place is initialized according to the true condition that whether it is true or false. The function is called in the console.log and the object value is passed.
46). What will be the output of the following JavaScript code?
[A]7.25
[B] -7.25
[C]7
[D]-7
Show Answer
Correct Answer: 7.25
Notes:
Answer: a
Explanation: The abs() method returns the absolute value of a number. The method is find in the math library of Javascript.
47). What will be the output of the following JavaScript code?
[A]125
[B]25
[C]5
[D]Error
Show Answer
Correct Answer: 5
Notes:
Answer: c
Explanation: cbrt return the cubic root of a number. The method is find in the math library of Javascript.
48). What will be the output of the following JavaScript code?
[A]1.01
[B]1.047
[C]1.00
[D]1.4
Show Answer
Correct Answer: 1.047
Notes:
Answer: b
Explanation: The acos() method returns the arccosine of a number as a value value between 0 and PI radians. If the parameter x is outside the range -1 to 1, the method will return NaN.