I. This set of questions focuses on the statements in JavaScript
1) Which type of JavaScript language is ___
- Object-Oriented
- Object-Based
- Assembly-language
- High-level
Clarification: JavaScript does not qualify as a purely object-oriented programming (OOP) language like PHP, Java, or several other programming languages, even though it is categorized as an object-based language. It falls short of being an OOP language due to the absence of three fundamental characteristics common to object-oriented programming languages: polymorphism, encapsulation, and inheritance.
2) What is the accurate output generated by the subsequent JavaScript code:
varx=5,y=1
var obj ={ x:10}
with(obj)
{
alert(y)
}
- Error
Clarification: The result produced by the code snippet mentioned earlier will be one. This occurs because the interpreter initially looks within "obj" for the property (y). However, since it does not locate "y" within "obj," it resorts to a value that is accessible outside of the object, which is present in the provided code.
3) Which one of the following also known as Conditional Expression:
- Alternative to if-else
- Switch statement
- If-then-else statement
- immediate if
Clarification: A conditional expression is capable of assessing only two outcomes, which are either true or false, determined solely by the assessment of the specified condition.
4) Out of the JavaScript code snippets provided below, which one demonstrates greater efficiency:
Code A
for(var number=10;number>=1;number--)
{
document.writeln(number);
}
Code B
var number=10;
while(number>=1)
{
document.writeln(number);
number++;
}
- Code 1
- Code 2
- Both Code 1 and Code 2
- Cannot Compare
Clarification: The first code snippet is expected to demonstrate greater efficiency. In reality, the second code may run into a runtime error since the variable "number" will never reach a value that is equal to or less than one.
5) In JavaScript, what is a block of statement?
- Conditional block
- block that combines a number of statements into a single compound statement
- both conditional block and a single statement
- block that contains a single statement
Response: (b) a block that consolidates multiple statements into one comprehensive compound statement
Clarification: A block of statements can be defined as a collection of zero or more statements. Typically, a block of statements is understood as "a construct that aggregates one or multiple statements into a single entity for the purpose of simplicity and organization."
6) When interpreter encounters an empty statements, what it will do:
- Shows a warning
- Prompts to complete the statement
- Throws an error
- Ignores the statements
Explanation: In JavaScript, when the interpreter comes across an empty statement, it typically disregards it or does not react to that statement. However, empty statements can also be quite beneficial; for instance, they can be utilized to construct loops that perform no operations.
7) The "function" and " var" are known as:
- Keywords
- Data types
- Declaration statements
- Prototypes
Clarification: The keywords "function" and "var" serve as declaration statements. They are utilized for defining and declaring variables and functions at any point within the program.
8) In the syntax of the switch statement provided below, which operator is utilized to compare the Expression with the labels?
switch(expression)
{
statements
}
- equals
- equals
Clarification: The strict equality operator yields true exclusively when both operands share the same type and their values are identical. During the execution of the switch statement, the expression's value is determined and subsequently compared against the case labels, searching for a case where the evaluated expressions result in an equivalent value (with the comparison being carried out using the === operator).
9) What will occur if the subsequent JavaScript code is run?
var count =0;
while (count <10)
{
console.log(count);
count++;
}
- An error is displayed
- An exception is thrown
- The values of count variable are logged or stored in a particular location or storage
- The value of count from 0 to 9 is displayed in the console
Response: (c) The values associated with the count variable are recorded or saved in a specific location or storage area.
Clarification: The method "console.log" referenced in the preceding function is among the built-in functions of JavaScript. It accepts values as its parameters and presents those argument values in the console when the script is executed.
10) What is the expected output for the JavaScript code shown below:
Int x=8;
if(x>9)
{
document.write(9);
}
else
{
document.write(x);
}
- Undefined
Explanation: The "if-else" construct is a type of conditional statement found in JavaScript, similar to its counterparts in various programming languages. In this scenario, the condition checked in the "if" statement resolves to false, leading to the execution of the code defined in the else block. Conversely, if the condition assessed in the "if" statement turns out to be true, then the code specified within the if block will be executed.
11) What is the correct output generated by the following JavaScript code:
var grade='C';
var result;
switch(grade)
{
case'A':
{
result+="10";
break;
}
case'B':
{
result+=" 9";
break;
}
case'C':
{
result+=" 8";
break;
}
default:
result+=" 0";
}
document.write(result);
Clarification: The provided program's code employs a switch statement, where the expression's value is assessed against the defined case labels. Should the value correspond to any of the case labels, the code associated with that specific case will be executed; if not, the instructions outlined in the default case will be executed. Additionally, it is significant to note that switch statements can serve as a substitute for "if-else" statements, helping to simplify the code and minimize its length.
12) What is the accurate output of the subsequent JavaScript code:
var grade='D';
var result;
switch(grade)
{
case'A':
result+="10";
case'B':
result+=" 9";
case'C':
result+=" 8";
case 'D'
result+=" 6";
default:
result+=" 0";
}
document.write(result);
Explanation: Upon examining the provided code closely, it becomes evident that the "break" statement is absent following any of the case labels. This indicates that when the subsequent program is executed, all the cases that follow "A" will be executed as well.
13) What is the accurate output generated by the following JavaScript code:
var x=3;
var y=2;
var z=0;
If(x==y)
document.write(x);
elseif(x==y)
document.write(x);
else
document.write(z);
- Error
Clarification: The "if-and if" statement serves the purpose of evaluating multiple conditions simultaneously. This construct is an enhancement of the "if-else" statement and is often referred to as the "if-else ladder." By utilizing this structure, we can broaden the "if-else" statement to assess a variety of conditions.
14) What is the correct output produced by the subsequent JavaScript code:
var grade='Z';
var result;
switch(grade)
{
case'A':
result+="10";
case'B':
result+=" 9";
case'C':
result+=" 8";
default:
result+=" 0";
}
document.write(result);
Explanation: The switch case statement is comprised of multiple cases, including the Default case, which serves as one of the options. The default case is executed solely when none of the other cases correspond with the value of the expression.
II. This set of questions focuses on the variables in JavaScript
15) Which of the following variables takes precedence over the others if the names are the same?
- Global variable
- The local element
- The two of the above
- None of the above
Clarification: In JavaScript, when a local variable shares the same name as a global variable, the local variable will override the global variable in terms of priority.
16) Which one of the following is the correct way for calling the JavaScript code?
- Preprocessor
- Triggering Event
- Function/Method
Clarification: The JavaScript code can be executed by directly invoking the function associated with the particular element on which the execution of the JavaScript code is intended. Additionally, there are numerous alternative methods to trigger JavaScript execution, including submit, onclick, onload, and others.
17) Which of the following type of a variable is volatile?
- Mutable variable
- Dynamic variable
- Volatile variable
- Immutable variable
Clarification: Variables that can have their values altered are referred to as mutable variables. In JavaScript, only arrays and objects exhibit mutability; primitive values, on the other hand, do not possess this property.
18) Which of the following options serves as a prefix for hexadecimal literals?
- Both 0x and 0X
Clarification: Typically, both X and x can represent hexadecimal values, which means that any integer literal that starts with either 0X or 0x signifies a hexadecimal number.
19) When there is an indefinite or an infinite value during an arithmetic computation in a program, then JavaScript prints______.
- Prints an exception error
- Prints an overflow error
- Displays "Infinity"
- Prints the value as such
Clarification: When the outcome of an arithmetic expression exceeds the maximum representable value in JavaScript, the language will output infinity. Likewise, if a numerical computation results in a value that is greater than the lowest representable negative number, JavaScript will display negative infinity.
20) In the JavaScript, which one of the following is not considered as an error:
- Syntax error
- Missing of semicolons
- Division by zero
- Missing of Bracket
Clarification: Indeed, it is accurate to state that dividing any integer by zero does not generate an error in JavaScript. Instead, the output will be infinity. Nonetheless, there is an exception within JavaScript; when zero is divided by zero, it does not yield any defined value. Consequently, the outcome of this particular calculation is a unique value referred to as "Not a Number" (commonly abbreviated as NaN), which is displayed as NaN.
21) Which of the following givenfunctions of the Number Object formats a number with a different number of digits to the right of the decimal?
- toExponential
- toFixed
- toPrecision
- toLocaleString
Explanation: The "toFixed" function modifies the specified number by formatting it to a defined quantity of decimal places.
22) Which of the following number object function returns the value of the number?
- toString
- valueOf
- toLocaleString
- toPrecision
Clarification: The function "valueOf" provides the value corresponding to the argument that was supplied to it.
23) Which of the following function of the String object returns the character in the string starting at the specified position via the specified number of characters?
- slice
- split
- substr
- search
Clarification: The function "Subtr" in JavaScript is designed to retrieve the characters from a string commencing at a defined position for a specified count of characters.
24) In JavaScript the x===y statement implies that:
- Both x and y are equal in value, type and reference address as well.
- Both are x and y are equal in value only.
- Both are equal in the value and data type.
- Both are not same at all.
Response: (c) Both possess identical values as well as the same data type.
Clarification: The "===" operator is referred to as strict equality comparison, which evaluates to true only when both the type and value of the operands are exactly identical.
Program
<!DOCTYPE html>
<html>
<head>
<H1>The concept of the "===" stement</H1>
</head>
<body>
<script>
var x=0,y=0;
var a=0, b=1;
if(x===y){
document.write(true);
}
else{
document.write(false);
}
if (a===b){
document.write(true);
}else
{ document.write(false);
}
</script>
</body>
</html>
Output
True
False
25) Choose the correct snippet from the following to check if the variable "a" is not equal the "NULL":
- if(a!==null)
- if (a!)
- if(a!null)
- if(a!=null)
Clarification: The "==" operator returns true only when both the type and content of the operands are identical. This operator is frequently utilized to assess the equality of two operands; however, it does not consider the data types of the variables involved. Conversely, the "!==" operator is referred to as "non-equal" and is employed in this scenario to compare 0 with NULL. The result will be either true or false, contingent upon the specified conditions.
26) Suppose we have a text "human" that we want to convert into string without using the "new" operator. Which is the correct way from the following to do so:
- toString
- String(human)
- String newvariable="human"
- Both human.toString and String(human)
Response: (d) Both human.toString and String(human)
Clarification: There exist three prevalent methods for transforming text into strings: value.toString, "" + value, and String(value). We can convert text to a string without employing the "new" operator by utilizing human.toString and the alternative method String(human).
27) Examine the JavaScript code provided and select the accurate output from the options below:
functioncomparing()
{
intx=9;
chary=9;
if(x==y)
returntrue;
else
returnfalse;
}
- compilation error
- false
- runtime error
- true
Clarification: The "==" operator adjusts both operands to a uniform type if they are of different data types before executing the comparison. In contrast, a strict comparison will return true exclusively when both the value and the data type of the operands are identical.
28) What will be the result of executing the following JavaScript code?
functioncomparison()
{
int number=10;
if(number==="10")
returntrue;
else
returnfalse;
}
- True
- false
- runtime error
- compilation error
Explanation: The "===" operator is referred to as a strict equality operator, which evaluates to true only when both the data types and the values of the operands are identical. For instance, in JavaScript, two strings are deemed strictly equal if they possess the same length, arrangement, and identical characters when they are compared.
29) Determine the accurate output produced by the following code snippet from the provided choices:
functionfun()
{
int y=10;
char z=10;
if(y.tostring()===z)
returntrue;
else
returnfalse;
}
- logical error
- false
- runtime error
- true
Clarification: It is possible to transform a non-string "integer" into a string format by utilizing the ".toString" method. The "===" operator, often referred to as strict equality, evaluates to true only when both the value and the type of the operands are identical. Consequently, this is the reason why the output from the previously provided code will result in true.
III. This set of questions focuses on operators and expressions of JavaScript
30) Examine the provided JavaScript code and select the appropriate output from the options below:
var string1 = "40";
varvalueinit=50;
alert( string1 +intvalue);
- 4090
- 4050
- Exception
Clarification: In JavaScript, the alert function performs type conversion, transforming the variable "valueinit" into a string. Subsequently, it concatenates this string with another string and presents the result on the display. Therefore, the expected output in this scenario would be 4050.
31) In JavaScript, what will be used for calling the function definition expression:
- Function prototype
- Function literal
- Function calling
- Function declaration
Clarification: A function definition expression can be considered a type of "function literal," similar to how an object initializer is categorized as a type of "object literal." This function definition expression, or function literal, is composed of the keyword Function, succeeded by a list of identifiers (or parameter names) that are separated by commas within parentheses, and a concise block of JavaScript code (commonly referred to as the function body or definition) that is contained within curly braces.
32) Which of the following one is the property of the primary expression:
- Contains only keywords
- basic expressions containing all necessary functions
- contains variable references alone
- stand-alone expressions
Clarification: In JavaScript, primary expressions, often referred to as the most basic expressions, are those that stand alone and do not comprise any simpler expressions. Examples of primary expressions include variables, constants, or literal values, as well as specific keywords from the language.
33) Take a look at the subsequent segment 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".
- test(text)
- equals(pattern)
- test(pattern)
- text==pattern
Clarification: The specified pattern is utilized on the string "text" that is situated within the parentheses.
34) Which one of the following is used for the calling a function or a method in the JavaScript:
- Property Access Expression
- Functional expression
- Invocation expression
- Primary expression
Explanation: The invocation expression represents a syntax feature in JavaScript utilized for executing a function or calling a method. It consistently begins with the function expression, which specifies the particular function intended to be called or executed.
35) The "new Point(3,2)", is a kind of _______ expression
- Object Creation Expression
- Primary Expression
- Invocation Expression
- Constructor Calling Expression
Clarification: The expression used for object creation not only generates a new object but also calls a method referred to as a constructor, which serves to set up the properties of that object. These object creation expressions resemble invocation expressions but are distinguished by being preceded by a keyword known as New.
36) Which one of the following operator is used to check weather a specific property exists or not:
- Exists
- exist
- within
Explanation: Within JavaScript, the "in" operator serves the purpose of verifying the existence of a particular property. This operator is frequently utilized in looping constructs to iterate over both arrays and objects.
37) Identify which of the following is a ternary operator:
Clarification: In JavaScript, there exists only a single ternary operator, referred to as the conditional operator, which merges three distinct expressions into a single expression. Furthermore, this conditional operator can serve as a substitute for traditional "if else" statements.
38) "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_____.
- Properties
- Prototypes
- Definition
- Lvalue
Clarification: The phrase "lvalue" originates from historical terminology, indicating "an expression that can validly be positioned on the left-hand side of an assignment expression." In JavaScript, the attributes of objects, elements, and variables qualify as lvalues.
39) What is the output produced by the following JavaScript code?
function display1(option)
{
return(option ? "true" : "false");
}
bool ans=true;
console.log(display1(ans));
- False
- True
- Runtime error
- Compilation error
Explanation: In the subsequent JavaScript code, the symbol "?" is referred to as the "ternary operator." This operator serves the purpose of selecting one option from two available choices. Additionally, it is frequently employed to create more concise and straightforward code, as it can serve as a substitute for traditional "if else" statements.
40) Which of the following represents the accurate output for the provided JavaScript code:
var obj=
{
length:20,
height:35,
}
if('breadth' in obj === false)
{
obj.breadth = 12;
}
console.log(obj.breadth);
- Error
- Undefined
Clarification: In the JavaScript code presented above, the "in" operator is utilized to verify the existence of a particular property. If the specified property is located, it yields true; if not, it results in false.
41) What is the accurate output for the subsequent JavaScript code provided below:
functionheight()
{
var height=123.56;
var type =(height>=190)?"Taller":"Little short";
return type;
}
- 123.56
- Taller
- Little shorter
Clarification: In the code provided above, the ternary operator is utilized, which operates on three operands. The instruction in the ensuing code assigns the string "little shorter" to the variable type, which is subsequently returned by the function.
42) Which of the following represents the correct output for the provided JavaScript code:
string X= "Good";
string Y="Evening";
alert(X+Y);
- Good
- Evening
- GooodEvening
- undefined
Clarification: The alert function is frequently employed for showcasing the value (or message) provided as an argument within the "dialog box" of a web browser. In this context, the alert function merges the two supplied strings and outputs them as a unified string.
43) Among the following options, identify the correct output that corresponds to the provided JavaScript code:
functionoutputfun(object)
{
var place=object ?object.place: "Italy";
return "clean:"+ place;
}
console.log(outputfun({place:India}));
- Error
- clean:Italy
- clean:India
- undefined
Clarification: In the code provided below, the ternary operator "?" plays a role in evaluating the values, which in turn determines (or initializes) the placement based on the evaluation of the true condition, returning either true (1) or false (0).
44) Which of the following represents the accurate output for the provided JavaScript code:
<p id="demo"></p>
<script>
functionourFunction()
{
document.getElementById("demo").innerHTML=Math.abs(-7.25);
}
</script>
- -7.25
Clarification: In the code provided, the function "abs" is utilized, which produces absolute values as results; therefore, the accurate choice is c. In JavaScript, the "abs" function is part of the library known as Math.
45) Which of the following represents the accurate output for the JavaScript code provided below:
<p id="demo"></p>
<script>
function Function1()
{
document.getElementById("demo").innerHTML=Math.cbrt(792);
}
</script>
- Error
Clarification: In the code presented above, the method "cbrt" is utilized, which computes the cube root of the number provided within the parentheses as its argument. The "cbrt" function is one among various methods included in the math library available in JavaScript.
46) Which of the following represents the accurate output for the provided JavaScript code?
<p id="demo"></p>
<script>
functionmyFunction()
{
document.getElementById("demo").innerHTML=Math.acos(0.5);
}
</script>
Clarification: The function "acos" utilized in the preceding example computes the arccosine of the input value provided as an argument. The output generated by this function is constrained within the range of 0 to PI radians. If the input value is outside the permissible range of -1 to 1, the "acos" function will yield NaN, which stands for Not a Number.
47) When we evaluate the comparison of "one" against "8" using the less than operator, the result will be that "one" <8)?
- False
- True
- Undefined
48) Which one of the following is known as the Equality operator, which is used to check whether the two values are equal or not:
Explanation: The "==" called the equality operators, it returns true if both the value are equal otherwise it returns false.
49) Which one of the following operator returns false if both values are equal?
- All of the above
Explanation: The "!=" operators returns false if both the given values are equal.
50) In a case, where the value of the operator is NULL , the typeof returned by the unary operator is___.
- undefined
- string
- boolean
- object
Explanation: In all cases, where the operator's value is NULL, then unary operator always returns the typeof object.
51) Check whether the following given statements for the Strictly equal operator are true or false:
a) If the data type of two values are equal, they are Equal.
b) If both values are undefined and both are null, they are Equal.
- False True
- False False
- True False
- True True
Explanation: The first statement does not follow the properties of strictly equal (===)operator, but second statement follows.
52) Which one of the following is correct output for the following javascriptcode:
3)
- Letsfindout 40
- Letsfindout40
- Exception
Explanation: 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.
53) Which one of the following is not a keyword:
- with
- debugger
- use strict
Explanation: The "use strict" is a type of directive which was introduced in ECMAScript5 and as we all know that directives are not the statements because they do not include any language keywords.
54) Which one of the following symbol is used for creating comments in the javascript:
- \ \
- \ /
Explanation: The single line comments always starts by the "//"" and any text written in between the "// "and the end of the line is considered as comment and ignored by the JavaScript.
IV. This set of questions focuses on "Loop" statements in JavaScript
55) Which of the following is the correct output for the following JavaScript code:
varx=5,y=1
var obj ={ x:10}
with(obj)
{
alert(y)
}
- Prints the numbers in the array in the reverse order
- Prints the numbers in the array in specific order
- Prints "Empty Array"
- Prints 0 to the length of the array
Explanation: As we all know, the "do-while" statement creates a loop that runs at least once even if the given condition is not satisfied. This is because it runs for the first time before checking the condition, and then executes until the condition becomes false. Therefore, it traverses the array and prints the element of the array on the screen in a specific order.
56) Which one of the given code will be equivalent for the following JavaScript code:
1)
a) Code A
for(var number=10;number>=1;number--)
{
document.writeln(number);
}
b) Code B
var number=10;
while(number>=1)
{
document.writeln(number);
number++;
}
C) Code C
switch(expression)
{
statements
}
d) Code D
var count =0;
while (count <10)
{
console.log(count);
count++;
}
Explanation: The variable in the code A working same ( e.g. traversing the array from the 0 index value) just like it working in the above code. In addition, we can also use the "For-in" loop statement for performing the same task more efficiently.
57) What are the three important manipulations for a loop on a loop variable?
- Updation, Incrementation, Initialization
- Initialization, Testing, Incrementation
- Testing, Updation, Testing
- Initialization, Testing, Updation
Explanation: In the "For" loop statement, the Initialization, Testing, and Updating(and in the same order) are the most significant manipulations. First of all, the Initialization of the variable is done, then the condition gets tested, and after executing the code written in between curly braces, variable's value gets incremented.
58) If the following piece of JavaScript code is executed, will it work if not, what kind of possible error can occur?
Int x=8;
if(x>9)
{
document.write(9);
}
else
{
document.write(x);
}
- Yes, it will work fine
- No, this will not iterate at all
- No, it will throw an exception as only numeric's can be used in a for loop
- No, it will produce a runtime error with the message "Cannot use Linked List"
Explanation: In the above-given code, the For loop statement is used for traversing the linked list data structure, which returns the last element of the list. So it is definitely going to work without throwing any exception.
59) What is the role of the "continue" keyword in the following piece of JavaScript code?
The continue keyword restarts the loop
- The continue keyword restarts the loop
- The continue keyword skips the next iteration
- The "continue" keyword breaks out of the loop
- It is used for skipping the rest of the statements in that particular iteration
Explanation: The continue keyword does not get exit from the loop just like break keyword does. It skips the upcoming statements in that iteration form where it gets encountered, and instead of exiting the loop, it moves to the next iteration.
60) Which one of the following is not considered as "statement" in the JavaScript?
- use strict
- debugger
- with
Explanation: In JavaScript, the "use strict" is not a keyword because it not includes any language keywords. However, it is a directive that is introduced in the ECMAscript5 version of the javascript. The "use strict" can be used only in the beginning of the script or in the beginning of the function where no actual keywords are mentioned yet.
61) What if we define a "for" loop and it removes one of the properties that has not yet been enumerated?
- The removed property will be stored in a cache
- The loop will not run at all
- That property will be enumerated
- That specific property will not be enumerated
Explanation: If the body of the "for" loop removes any of the property that has been not enumerated yet, normally that property not gets enumerated. If the object of the "for" loop statement creates a new property on the object, that property is usually not enumerated.
62) Which of the following is the correct response by the interpreter in a jump statement when an exception is thrown?
- The interpreter will jump to the one of the nearest enclosing exception handler
- The interpreter will throw another exception
- The interpreter will stop working
- The interpreter throws an error
Explanation: In the jumping statement, when an exception is thrown, the interpreter jumps to the closest enclosing exception handler, which may possibly exist in the same function.
63) Which one of the following is the possibly correct output for the given JavaScript code?
var grade='C';
var result;
switch(grade)
{
case'A':
{
result+="10";
break;
}
case'B':
{
result+=" 9";
break;
}
case'C':
{
result+=" 8";
break;
}
default:
result+=" 0";
}
document.write(result);
- error
Explanation: In the "for" loop statement, first of all, the variable's initialization takes place and checks the condition of the given expression. After that, the statements written in the body of the "for" loop statement are executed. The value of the variable gets incremented after each iteration until the condition gets false.
64) Which one of the following is the correct output for the given JavaScript code?
var grade='D';
var result;
switch(grade)
{
case'A':
result+="10";
case'B':
result+=" 9";
case'C':
result+=" 8";
case 'D'
result+=" 6";
default:
result+=" 0";
}
document.write(result);
Explanation: In the "while" loop statement, the condition is first checked before executing the statements written in the loop's body. Generally, the value of the counter variable incremented at the end of the body of the "while" loop, whereas the statements are executed first.
65) Which of the following options would be the correct output for the given JavaScript code?
- 5555
- 5555
- 5321
- 531-1-3
Explanation: The value of variable x will decrease 2 times when the loop body executes and the body will execute 4 times until the variable's value of j is 0.
Output
66) Which of the following options would be the correct output for the given JavaScript code?
error
- error
Explanation: The variable's value will increase until it gets equal to 10, then the control will exit the loop's definition. There are no other statements to be executed in the definition of the loop,only the value of the variable "x" will be incremented, and the output will be 10.
67) Consider the following piece of JavaScript code:
var x=3;
var y=2;
var z=0;
If(x==y)
document.write(x);
elseif(x==y)
document.write(x);
else
document.write(z);
What is the role of the "debugger" statement?
- It is kind of keyword which is used to debug the entire program at once
- It will do nothing, although it is a breakpoint
- It will debug the error in that statement
- All above mentioned
Explanation: A program can contain a number of mistakes like syntax errors, logical errors, etc, and for many of them, there are no alert messages and also no indications to find the mistakes. So, to find the location of the error and to correct that, developer setups the breaking points at the doubted code using the debugger window.
V. This set of questions focuses on serialization and object attributes in JavaScript
68) Which one of the following is the correct output for the given JavaScript code?
error
- error
- true
- false
Explanation: Object.preventExtensions only prevents adding new properties that have ever been added to an object. This change is not reversible, meaning that once an object becomes non-extensible, it cannot be changed to an extensible.
69) Which one of the following is the correct output for the given JavaScript code?
var grade='Z';
var result;
switch(grade)
{
case'A':
result+="10";
case'B':
result+=" 9";
case'C':
result+=" 8";
default:
result+=" 0";
}
document.write(result);
- Runtime error
- Compilation error
Explanation: The object.freeze method is used to "freeze" the properties of an object and also avoids adding new properties to it. This avoids manipulation/change in all existing values, properties, and attributes
70) Which one of the following is the correct output for the given JavaScript code?
- False
- False
- true
- error
Explanation: In JavaScript, the "Object.is method is one of the built-in methods. This method is used to know whether two values are the same or not. There is also a specific pre-defined method that compares the values and it returns a Boolean value as the result, which indicates whether two arguments are the same or not.
71) What will be the output of the following JavaScript code?
<!DOCTYPE html>
<html>
<head>
<H1>The concept of the "===" stement</H1>
</head>
<body>
<script>
var x=0,y=0;
var a=0, b=1;
if(x===y){
document.write(true);
}
else{
document.write(false);
}
if (a===b){
document.write(true);
}else
{ document.write(false);
}
</script>
</body>
</html>
- true 21
- true false
- false false
- true true
Explanation: In JavaScript, "Object.getOwnPropertDescriptor" provides the ability to query information about a property in detail. It returns a property's descriptor for that property, which directly presents on an object and not present in the object's prototype of the certain object.
72) Which one of the following is the correct output for the given JavaScript code?
- Error
- Error
Explanation: The method "Object.getOwnPropertySymbols" used in the above program, returns a whole array of symbol properties, that are directly found on an object. In general, it returns an empty array, unless we have already set symbol properties on the object.
73) What is the basic purpose of the "toLocateString" method?
- It returns a localised object representation
- It returns a localized string representation of the object
- It return a local time in the string format
- It return a parsed string
Explanation: The "ToLocatestring " method is one of the pre-defined methods of JavaScript, which returns the localized string representation of the object. For example the "date.toLocaleSting is also one of the predefined functions of the javascript that is used for converting time and date into a string.
74) What kind of work is being performed in the following given part of JavaScript's code?
- Object-Oriented Programming
- Object Encapsulation
- Object Encoding
- Object Abstraction
- Object Serialization
Explanation: In the above give piece of code, the task of Object Serialization is being performed. In this task, the object's state converted into a string, that also can be restored if needed. Another method used in the above-given code is "JSON.parse", which parses a JSON string, object described by the string or constructing javascript value.
75) A set of unordered properties that, has a name and value is called______
- String
- Array
- Serialized Object
- Object
Explanation: The Objects in the JavaScript are considered as a set of unordered related data(or properties), reference types, in the form of "key: value" pairs. Hence each of the property contains a name and value.
76) A collection of elements of the same data type which may either in order or not, is called _____.
- String
- Array
- Serialized Object
- Object
Explanation: An array is a collection of different elements that are of the same data-type. It can place elements in ascending order, in descending order or random order. We can interpret it as a container that contains data items of the same data-type.
77) Every object contains three object attributes that are _______.
- Prototype, class, object's extensible flag
- Prototype, class, objects' parameters
- Class, parameters, object's extensible flag
- Native object, Classes and Interfaces and Object's extensible flag
Explanation: In general, each object contains three object associated attributes:
Object prototype: It is kind of reference/indication to another object from which properties are inherited.
Object class: It is a kind of string which classifies the type an object.
Object's extensible flag: It simply specifies that whether some new properties are added to the object.
78) What will be the output of the following JavaScript code?
True
False
- Properties
- property names
- property values
- objects
Explanation: In the above-given code, a nested object (an object inside in the other object) is used, and "firstname","lastname" are the properties. The value of that individual property is itself an object.
79) The linkage of a set of prototype objects is known as______
- prototype stack
- prototype
- prototype class
- prototype chain
Explanation: Suppose, A Time.prototype inherits some properties from the Object.prototype,So a Time Object created by using new Time holds properties from both the object Time.prototype and Object.prototype. Hence this connected series of prototype object is known as prototype's chain.
80) In the following line of code, what we will call the "datatype" written in brackets?
article[datatype]=assignment_value;
- An String
- A integer
- An object
- Floating point
Explanation: In the above-given line of code, the value within the square brackets is used for accessing the property of that object. While using square brackets, the expression always evaluates to the string, or in the form of a value that is converted into a string.
81) To know about an object, whether the object is a prototype (or a part of a prototype chain) of another object, the user can use_______
- ==operator
- equals method
- === operator
- isPrototypeOf method
Explanation: The prototype is a kind of global property that is available with nearly all objects. In order to know about an object, whether the object is a prototype (or a part of a prototype chain) of another object, the user can use the "isPrototypeOf" method. For example, if the user wants to find out about z whether it is a prototype of "s" or not, user can write z.isPrototypeOf(s).
82) In the following given line of code, the prototype representing the_____
functionx(){};
- Function x
- Prototype of a function
- A custom constructor
- Not valid
Explanation: In general, every object instance has a unique property which indicates the constructor function that created it. A "custom" constructor is a kind of constructor that not needed any argument (or we can say constructor without argument) and it is created by the compiler automatically at the time of object creation if it is not created by user.
VI. This set of questions focuses on Arrays in JavaScript
83) What will be the output obtained by "shift " in the given code of JavaScript?
1)
- Exception is thrown
- [4,5]
- [3,4,5]
Explanation: In JavaScript, the "unshift"," shift" methods work like just as push and pop but with a slight change, unlike the push and pop the unshift, unshift both insert and remove a data item from the beginning instead of from the end of the array. The "unshift" is used for inserting the data element/item in the beginning of the array while the "shift" method shifts the data item to the beginning of the array from the higher index, empty the last index of the array and returns the updated length of the array.
In the process of shifting, the data element is removed from the beginning of the array, and all subsequent elements are shifted and the new length of the array is returned.
84) Which one of the following options is the correct output for the given code of java script?
error
- error
Explanation: The "forEach" method used in the above given code is one of the built-in method of JavaScript. This method traverses the whole array just like we use the "for" loop to traverse the array. The term traverse is referred to "going or accessing each element of the array at least one time".
85) Which one of the following options is the correct output for the given code of JavaScript?
3.
- three
- error
Explanation: The "shift" method used in the given code is one of the predefined method in JavaScript. This method is used to remove the data elements from the beginning and return it along with the new length of array. We can say that the "shift" method works like the "pop" method except it removes the data element from the starting of array unlike the "pop" which removes from the end of the array.
86) Which one of the following options is the correct output for the given code of JavaScript?
1.
- 1, 2, 3,4
- 4, 3, 2, 1
Explanation: The "reverse" method used in the above given code is one of the predefined methods of the JavaScript, which is used to shift the data elements of an array in a reverse order.
87) Which one of the following options is the correct output for the given code of javascript?
Error
- Error
- 5, 6, 7
- 4, 5, 6,
- 4, 5, 6, 7
Explanation: The "slice" method used in the above program a built-in function of the JavaScript and it is used to delete/remove the data items from the array. In general, it requires two arguments,in which first one for starting point and another one for the ending point. For example, consider the following given code:
1.
Output
Lemon,Apple
However, we can see that in given question only one argument is passed, so it will definitely result in an error.
88) Which one of the following method or operator is used for identification of the array?
- Typeof
- isarrayType
Explanation: In JavaScript, the "typeof" operator is used for knowing the data type of the specified operand that can be a data structure or literal like an object, method, and variable.
89) For which purpose the array "map" methods is used ?
- It used for mapping the elements of another array into itself.
- It passes each data-item of the array and returns the necessary mapped elements.
- It passes the data-items of an array into another array.
- It passes every element of the array on which it is invoked to the function you specify, and returns an array containing the values returned by that function.
Explanation: The "map" method is one of the built-in methods of the JavaScript that is used for mapping the data-items of the array, which can be used later for some other purpose. It passes every element of the array on which it is invoked to the function we specify, and returns an array containing the values returned by that function.
90) Both the "rduucedRight" and "reduce" methods follow which one of the following common operation?
- inject and fold
- filter and fold
- finger and fold
- fold
Explanation: In JavaScript, the reduce method reduces the size of the array to a single value. This method executes a provided specific method on each data-item or element of the array in the left to right manner. It stored the value returned by the function in an accumulator. However, it does not execute the provided function on the array's elements, which has no value.
The "reduceRigth" method does the same work of reducing the array to a single individual value and calls or executes a certain function on each element of the array but in the right to left manner. It also stores the value returned by the function in an accumulator, such as total or result.
So as we can see that both the methods "reduce" and "reduceRight" almost do the same work that is known as inject and fold.
91) Which one of the following given task is performed by the "pop" method of the array?
- Itupdates the element of the array
- it increments the total length of the array by 1
- It prints the first element and made no impact on the length of the array
- updates the element removes one element of an array on each time the "pop" function called
Explanation: The "pop" method is used for removing the last element of the array, or we can say, it removes/deletes the element from the tail-side of an array. Hence every time the "pop" method is called, the value of the array's length gets decremented by one.
92) What will happen if we use the "join" method along with the "reverse" method?
- It will reverse and concatenates the elements of the array
- It will reverse the element and store the elements in the same array
- It will just reverse the element of the array
- It will store the elements of the specified array in the normal order
Explanation: The "array.join" method is one of the predefined methods of the JavaScript. It is used for joining the data-items of an array and converts them into a string. The "Reverse" method, which is used along with it, reverses the specified array, and it stores the array into the memory once it gets reversed.
93) What will be the output of the following given code of JavaScript?
- true true
- true true
- false true
- true false
- false true
Explanation: As we can see in the given code, the "x1" array is defined but with the null values by which we can easily access the index 0,1,2 of it. We can access the largest index of the array in which any value or even null value is defined. In the "x2" array, we cannot access the index 0 because the "x2" array is declared, but it is not defined till now.
94) What will happen if we execute the following piece of code?
4)
- The output will be 4 3 1
- The output will be 4 3 undefined 1
- It will result in an error
- It does not run at all
Explanation: In JavaScript, if user defines an array and does not define value of any element, there will be no error. But if user tries to print the element of the array whose value is not defined, it will print the "undefined" as the value of that element.
95) What output we may get if we execute the following JavaScript code:
0124
- 0124
- 01234
- It will throw a error
- No output
Explanation: In the above-given code, the "continue" keyword mentioned which is commonly used in loops for skipping the specific iteration of a loop and jumping to the next iteration of the loop without exiting the loop's body. As you can see in the above code when the value of variable "i" gets equal to the 3, the "continue" keyword executed and control skips current iteration and jump to the next iteration.
96) What will be the output of the following JavaScript code?
1.
- 1, 2, 3
- Error
- It will concatenate both the stings and print as 1, 2, 3, 4, 5, 6, 7, 8, 9 ,10
- It will print nothing
Explanation: In JavaScript, the "concat" is a predefined method which is used to join the values of two arrays. Both the arrays can contain string or the integers.
Example
functioncomparing()
{
intx=9;
chary=9;
if(x==y)
returntrue;
else
returnfalse;
}
Output
VII. This set of questions focuses on the functions and functional programming in JavaScript
97) What is the primary role of the "return " statement in a function body?
- It returns the value and continues executing rest of the statements
- It returns the value and stops the program execution
- Stops executing the function and returns the value
- It returns the value and stops executing the function
Explanation: In general, the "return" statement is the last statement in the body of function if the function is return-type. Whenever the return statement gets encountered in the definition of the function, the execution of the function will stop, and it returns the stored value to the statement where the function call has been made.
98) If a function which does not return a value is known as _____
- Static function
- Procedures
- Method
- Dynamic function
Explanation: Functions that do not return any value are known as void functions and are sometimes called processes.
99) The execution of a function stops when the program control encounters the _________ statement in the body of the function.
- return statement
- continue statement
- break statement
- goto statement
Explanation: Whenever a "return" statement is encountered by the program control inside the function's definition, it stops the execution of that function. Statements such as "break" and "continue" are commonly used in the definition of a loop to jump out of the loop (or to skip the rest statements inside the definition of the loop)
100) In which events/scenarios, A function name gets optional in JavaScript?
- When a function is defined as a looping statement
- When the function is called
- When a function is defined as expressions
- When the function is predefined
Explanation: A function name becomes optional when it is defined as an "Expression". For Example
Program
var s = function (a, b) {return a * b};
After a function has been stored in a variable, we can use that variable as a function
function
101) In JavaScript, the definition of a function starts with____
- With the Return type, Function keyword, Identifier and Parentheses
- With the Identifier and Parentheses
- With the Return type and Identifier
- With the Identifier and Return type
Explanation: The definition of any function always begins with a "keyword" function, followed by an identifier which is the name of the function as well as with a pair of parentheses that cover the list of identifiers. If the list of identifiers includes more than one identifier, they are separated by commas.
102) What happens if the return statement has no related expression?
- It will return a undefined value
- It will throw a exception
- It will return the 0 as the value
- It will throw a error
Explanation: Suppose a function that does not have a return statement in its definition returns a default value. Although the return statement is mentioned in the definition, but not associated with the expression, then it will return the value known as "undefined."
103) Which one of the following options is the correct output for the given code of JavaScript?
functioncomparison()
{
int number=10;
if(number==="10")
returntrue;
else
returnfalse;
}
- Prints the contents of each property of o
- Prints the address of elements
- Prints only one property
- Returns undefined
Explanation: The output of the above JavaScript code will be undefined.
104) Which one of the following code is equivalent to call a function "x" of the class "a" which have two arguments g and h?
- a,x(g,h);
- x(g) &&a.x(g);
- x(a,g);
- (g,h);
Explanation: If a function has more than one argument, it is separated by commas. The above code is an invoked expression: in which a function a.x and two arguments " g " and " h " are separated by commas.
105) Which one of the following code is equivalent to the following given code?
a.x(g,h);
- x (g) &&a.x (h);
- a [ "x" ] ( g , h );
- a (x )[ "g" , "h" ];
- x( g&&h );
Explanation: We can use the alternate code to perform the same task of accessing the properties of the object <a.x(g,h) is a<a>.a["x"] > and the parentheses will invoke the function "x" referenced within them.
106) Among the following choices, which one accurately represents the output produced by the provided JavaScript code?
functionfun()
{
var a=1;
var b=2;
return a*b;
}
document.write(fun());
- Error
Clarification: In JavaScript, the method document.write is a built-in function utilized for displaying output to the console. In this instance, an additional function is provided as an argument to the document.write method, which computes the product of the variables a and b.
107) Among the options listed below, which one accurately represents the output generated by the provided JavaScript code?
vararr=[1, 3, 5, 8 ,11];
var value =Math.max.apply(null,arr);
document.writeln(value);
Explanation: The "apply" function referenced in the code provided is a built-in method that accepts an array as its first argument and a second argument set to NULL. This method is designed to identify the maximum integer value present within the entire array.
108) Among the options provided, which one accurately reflects the output generated by the specified JavaScript code?
var person =
{
name: "James",
getName:function()
{
nreturnthis.name;
}
}
varunboundName=person.getName;
varboundName=unboundName.bind(person);
document.writeln(boundName());
- James
- compilation error
- runtime error
- undefined
Clarification: The "bind" method referenced in the previously provided code is utilized for generating a new function that inherently includes its own specified context.
109) Among the following choices, which one accurately represents the output produced by the provided JavaScript code?
function code(id,name)
{
this.id= id;
this.name= name;
}
functionpcode(id,name)
{
code.call(this,id,name);
}
document.writeln(newpcode(004,"James Deo").id);
- James Deo
- compilation error
- runtime error
- undefined
Clarification: The "call" function referenced in the previously provided code snippet is utilized to invoke a function while passing "this" as a parameter. It yields the result produced by the invoked function.
110) Which of the following choices represents the accurate output for the provided JavaScript code?
var pow=newFunction("num1","num2","return Math.pow(num1,num2)");
document.writeln(pow(2,3));
- Error
Clarification: The "pow" function utilized in the preceding code is among the pre-defined functions provided by JavaScript's mathematics library. This function takes two parameters, where the first parameter's value is raised to the exponent specified by the second parameter.
111) Which one of the following keywords is used for defining the function in the JavaScript?
- Void
- init
- main
- function
Clarification: In JavaScript, a function is established by utilizing the "function" keyword, succeeded by the name of the function and then the parentheses . Function names are permitted to include dollar signs, underscores, alphabetic characters, and even numerical digits.
112) In JavaScript, do the functions always return a value?
- Yes, functions always returns a value
- No, it is not necessary
- A number of functions return values by default
- some functions do not return any value
Response: (c) Several functions provide return values by default.
Clarification: In JavaScript, various functions that include a return statement are typically designed to return a value. Conversely, functions that lack a return statement in their definition generally do not yield any value; however, there are certain exceptions where some of these functions may still return a value by default, despite the absence of a return statement.
113) Among the options provided, which of the following code snippets accurately concatenates the strings that are supplied to the function?
A. Code 1
functionconcatenate()
{
returnString.prototype.concat('', arguments);
}
B. Code 2
functionconcatenate()
{
returnString.prototype.concat.apply('', arguments);
}
C. Code 3
functionconcatenate()
{
returnString.prototype.apply('', arguments);
}
D. Code 4
functionconcatenate()
{
returnString.concat.apply('', arguments);
}
Clarification: The "concat" function is a built-in method in JavaScript that facilitates the merging of two or more arrays. A key benefit of utilizing this function is that, rather than modifying the original array, it generates a new array. Similarly, the ".apply" method is also a built-in function, like "concat", and it accepts an array of arguments while treating each element within that array as a separate argument.
114) What values will be produced by the final statement in the provided code?
functionconstfun()
{
var fun =[];
for(vari=0;i<10;i++)
fun[i]=function(){returni;};
return fun;
}
var fun =constfun();
fun[5]()
Explanation: The code presented in the upcoming question generates a minimum of 10 closures, which are then stored in an array. These closures are defined within the same function call, allowing them to have shared access to the variable i. By the time the "constfun" method completes its execution, the value of the variable i is 10, and all closures reflect this value. Consequently, every function within the specified array of functions returns the identical value.
115) What will be the expected output from the subsequent JavaScript code?
<p id="demo"></p>
<script>
functionFunct()
{
document.getElementById("demo").innerHTML=Math.atan2(8,4);
}
</script>
- 1.01
- 1.10
- 1.05
- 1.11
Clarification: The "atan2" function utilized in the code provided computes the arctangent of the division of its two parameters, yielding a result in the range of -PI to PI radians. The resulting value indicates the counterclockwise angle, measured in radians (as opposed to degrees), between the positive X-axis and the coordinates (x,y).
116) What would be the appropriate output of the subsequent JavaScript code?
<p id="demo"></p>
<script>
functionmyFunc()
{
document.getElementById("demo").innerHTML=Math.asinh(1);
}
</script>
- 0.80
- 0.78
- 0.50
- 0.88
Clarification: The "asinh" function utilized in the provided code is a built-in method found within the math library of JavaScript. This function computes the hyperbolic arcsine of a numeric value.
117) What will be the outcome if we run the subsequent JavaScript code?
vartensquared=(function(x){return x*x;}(10));
- Memory leak
- Error
- Exception will be thrown
- Yes, perfectly
Clarification: The name of the function is not mandatory for functions that are established as expressions. Function expressions can occasionally be both declared and executed right away.
118) What will be the output when the following segment of JavaScript code is executed?
var string2Num=parseInt("123abc");
- Exception
- 123abc
Clarification: The method "parseIn" is a built-in function in JavaScript that interprets a string and subsequently produces an integer. Additionally, if the string does not initially contain an integer, it returns the first digit as 0.
119) Which of the following alternatives can be deemed a code equivalent to the code provided?
var o =newObject();
- var o= new Object;
- var o;
- var o = Object;
- Object o=new Object;
Clarification: In JavaScript, a unique instance of the "new" operator simplifies the syntax by permitting the omission of parentheses when invoking a constructor without any arguments. Consequently, users can forgo the empty parentheses in all scenarios of constructor calls where no arguments are provided.
120) In what way do the following lines of code vary from one another?
Code A
!!(obj1 && obj2);
Code B
(obj1 && obj2);
- The first line results in a real Boolean value whereas the second line merely checks for the existence of the objects
- Both the lines of code A and B will result in a Boolean value "False"
- Both the lines of code A and B will check just for the existence of the object alone
- Both the lines of code A and B will result in a Boolean value "True"
Response: (a) The initial line produces an actual Boolean value, while the subsequent line only verifies the presence of the objects.
Clarification: Code A will yield a result in the format of a "genuine" boolean value, as we initially execute the operation specified within the parentheses, followed by an immediate negation. Consequently, it implies that a false statement is rendered true.
Code B checks for the presence of obj1 and obj2. Additionally, it is important to note that it might not consistently yield a "true" boolean value. This implies that rather than exclusively returning true or false, it could lead to complications since values that evaluate to false could include an empty string or the number 0.
121) In the code snippet provided, what value is expected for the variable "a"?
var x =counter(), y = counter();
x.count()
y.count()
x.reset()
x.count()
y.count()
- Null
- Undefined
Clarification: The "counter" function utilized in the preceding code increases the variable's value by one with each invocation, while the "reset" function brings that variable's value back to zero. Thus, upon closer examination, it is evident that the "counter" method was executed twice on the variable "y," and the "reset" method was never invoked, resulting in the value of the variable y being 2.
122) Which of the provided choices can be regarded as the accurate output resulting from the execution of the subsequent code?
var addition=newFunction("number1","number2","return number1+number2");
document.writeln(addition(10,5));
- Error
Clarification: The "addition" function was established in the initial line of code utilizing the "new" property. In the subsequent line of code, the addition function is invoked with two parameters: 10 and 5, within the "document.write" method. This results in the output of the sum of the two parameters, which is returned by the "addition" function.
VIII. This set of questions focuses on the Closures in JavaScript:
123) Which one of the following is not a example of closures?
- Graphics
- Variables
- Functions
- Objects
Clarification: Every time a function is instantiated in JavaScript, a closure is also formed. Broadly speaking, we can assert that every closure is essentially a function, or conversely, every function embodies a closure. Additionally, each function is linked to a scope chain.
124) What will be the output produced by the function in the subsequent code?
var scope ="global scope";
functioncheckingscope()
{
var scope ="local scope";
functionf()
{
return scope;
}
return f;
}
- It will returns the value in scope
- It will returns value null
- It will returns an exception
- It will show an error message
Clarification: Every segment of code, whether it be a function or an entire script, is always linked to an entity known as a Lexical environment. Consequently, the JavaScript code presented in the preceding question will yield the value that is currently in scope.
125) What is the primary rule of the Lexical Scoping?
- Functions are always declared in the scope
- Variables are declared inside the function
- Functions are always declared outside the scope
- Functions gets executes using scope chain
Response: (d) Functions are executed utilizing the scope chain.
Explanation: The primary principle of lexical scoping is that in JavaScript, a function operates under the scope chain that was active at the time of its definition.
126) What is required in order to implement the Lexical Scoping?
- To reference the current scope chain
- Dereference the current scope chain
- Get the object
- Return the value
Clarification: It is essential to incorporate not only the code of that function within the internal state of the function's object but also to supply references to the existing scope chain.
127) Which one of the following utilize the CPU cycles in a massive manner?
- GUI (Graphic User Interface)
- Statically generated graphics
- Generic scoping
- Dynamically generated graphics
Clarification: The phrase "dynamically generated graphics" pertains to the creation of simulated movement, motion, or specific environments through the use of a computer. It can also be interpreted as a series of plots linked to time. Consequently, the graphics produced in this dynamic fashion from real-time data consume a significant portion of CPU resources.
128) In JavaScript, what kind of scoping is used?
- Literal scoping
- Sequential scoping
- Segmental scoping
- Lexical scoping
Clarification: In JavaScript, lexical scoping operates similarly to various other contemporary programming languages. This indicates that a function is executed utilizing the scope chain that was applicable at the time it was defined, rather than the variable scope that was in effect during its invocation or call.
129) What are the closures?
- Both Function objects and Scope where function's variables are resolved
- Scope where function's variables are resolved
- Function objects
- Function return value
Explanation: A closure can be defined as a combination of a function's object along with a scope (a collection of variable bindings) within which the variables of that function are determined. This configuration is known as the closure.
130) Which one of the following can be considered as the opposite approach of the Lexical Scoping?
- Dynamic scoping
- Literal scoping
- Static scoping
- Generic scoping
Clarification: Dynamic scoping can be seen as a contrasting methodology to lexical scoping. In dynamic scoping, the manner in which the code is structured is less significant; rather, what holds importance is the order of execution of the code. Each time a new function is executed, a fresh scope linked to that function is added to the stack, which is typically maintained alongside the function call stack. When a variable is accessed within the definition of a function, the system promptly examines each call stack to determine whether it yields a value.
131) Which one of the following algorithmic languages is not the lexical scoping standardized in?
- Html
- Pascal
- Modula2
Clarification: Lexical scoping is a standardized feature across all the algorithmic languages listed below, with the exception of HTML.
132) What will the result be when executing the following JavaScript code?
var o =newF(); // statement 1
o.constructor=== F // statement 2
- False
- True
Explanation: A "constructor" refers to a function that is a characteristic of any class, primarily utilized for creating objects of that specific class. In the code provided above, both statements 1 and 2 are generating an instance of the class.
133) Among the options provided, which one can be deemed the correct output for the subsequent JavaScript code?
const obj1 =
{
a:10,
b:15,
c:18
};
const obj2 =Object.assign({c:7, d:1}, obj1);
console.log(obj2.c, obj2.d);
- Undefined
- 18,1
- Error
Clarification: The "object.assign" function referenced in the preceding code is utilized for duplicating the properties and values from one object to a different object. In this case, the objects are assigned and copied based on their reference.
134) Which of the following POSIX signals generate events?
- SIGINT
- SIGDOWN
- SIGFLOAT
- SIGSHORT
Explanation: "SIGINT" is the correct answer.
135) Which HTML element is used to put the JavaScript code?
- <javascript>
- <js>
- <scripting>
- <script>
Clarification: "<script>" represents the accurate answer.
136) Which of the following statement is not correct in the case of JavaScript?
- JavaScript is a light-weighted and interpreted language.
- JavaScript is a high-level programming language.
- JavaScript is a case-sensitive language.
- JavaScript provides reasonable control to the users over the web browsers.
Response: (b) JavaScript is classified as a high-level programming language.
Clarification: JavaScript is classified as a high-level programming language.
137) Why is JavaScript called a structured programming language?
- Because all popular web browsers support JavaScript as they provide built-in execution environments
- Because it is an object-oriented programming language that uses prototypes rather than using classes for inheritance
- Because it follows the syntax and structure of the C programming language, which is a structured programming language
- Because it ignores spaces, tabs, and newlines that appear in JavaScript programs
Response: (c) This is due to its adherence to the syntax and structure characteristic of the C programming language, which is recognized as a structured programming language.
Clarification: "The correct response is that it adheres to the syntax and framework of the C programming language, which is classified as a structured programming language."
138) Which of the following is the correct syntax to print a page using JavaScript?
- print;
- print;
- print;
- print;
Clarification: The appropriate solution is "window.print;".
139) Which of the following is not a JavaScript Data Types?
- Boolean
- Undefined
- Number
- Float
Clarification: The appropriate response is "Float." In JavaScript, the language exclusively recognizes the following data types: Number, String, Boolean, Object, and Undefined.
140) Which of the following is the correct JavaScript syntax to access the element using HTML code?
- getElement ("availablecourse").innerHTML = "See the list of availablecourse";
- getElementById ("availablecourse").innerHTML = "See the list of availablecourse";
- getId ("availablecourse") = "See the list of availablecourse";
- getElementById ("availablecourse").innerHTML = See the list of availablecourse;
Response: (b) document.getElementById("availablecourse").innerHTML = "View the catalog of available courses";
Clarification: The statement document.getElementById("availablecourse").innerHTML = "See the list of availablecourse"; is indeed the accurate solution. To retrieve the content associated with that specific id, it is necessary to utilize .innerHTML to define this action, and ultimately substitute the existing content with the text contained within the quotation marks.
141) Which of the following function of the Array object is used to add one or more elements to the front of an array and returns the new length of the array?
- splice
- unshift
- sort
- toString
Clarification: The appropriate method is "unshift". This function is utilized to insert one or several items at the beginning of an array and subsequently provides the updated length of the array.
142) Which of the following syntax is correct to refer to an external script called "LFC.js"?
- <script source="LFC.js">
- <script ref="LFC.js">
- <script src="https://placehold.co/400x300/1abc9c/ffffff?text=Sample+Image">
- <script type="LFC.js">
Clarification: <script src="LFC.js"> is the accurate response. The attribute "src" is employed to denote any JavaScript file.
143) Which of the following syntax can be used to write "Hello World" in an alert box?
- alertBox("Hello World");
- msgBox("Hello World");
- alert("Hello World");
- msg("Hello World");
Clarification: The statement "alert('Hello World');" is the accurate response.
144) Which of the following is not a JavaScript framework or library?
- Polymer
- Meteor
- jQuery
- Cassandra
Clarification: "Cassandra" is the accurate response. It does not belong to the category of JavaScript frameworks or libraries. Instead, it is a distributed database developed by Apache.
145) Why does the name of JavaScript and Java are similar?
- JavaScript is a stripped-down version of Java.
- The syntax of JavaScript is loosely based on the syntax of Java.
- JavaScript and Java both are originated on the island of Java.
- None of the above
Response: (b) The structure of JavaScript's syntax is somewhat derived from the syntax of Java.
Clarification: "The structure of JavaScript is somewhat derived from the structure of Java" is the accurate response.
146) Which of the following is the correct statement of WHILE loop start?
- while (i <= 10)
- while (i <= 10; i++)
- while i = 1 to 10
- None of These
Clarification: The statement "while (i <= 10)" represents the accurate solution.
147) What was the original name of JavaScript when it discovered?
- LiveScript
- EScript
- JScript
- Mocha
Clarification: "Mocha" is the accurate response. Upon its inception, JavaScript was first referred to as Mocha, subsequently rebranded to LiveScript, and ultimately adopted the name JavaScript following a licensing agreement between Netscape and Sun. The name JavaScript was chosen because, during that period, it was developed as a scripting language intended to work alongside Java.
148) Which of the following is the correct way to write a comment in JavaScript code?
- //This is a comment
- /This is a comment/
- $This is a comment$
- This is a comment
Clarification: //This is a comment represents the accurate choice.
149) What will be the result of executing the following Javascript code?
var string1 = "Fee";
var intvalue = 10000;
alert( string1 + intvalue );
- Fee 10000
- 10000
- Fee10000
- Exception
Clarification: The accurate response is Fee10000. Following the process of concatenation, the two strings are displayed as a single concatenated string.
150) Which of the following JavaScript operator is used to assign a value to a variable based on some condition?
- Assignment operator
- Bitwise Operator
- Conditional operator
- Logical Operator
Clarification: The appropriate answer is the conditional operator.
151) Which of the following variables are used in JavaScript programs?
- Varying randomly
- Causing high-school algebra flashbacks
- Storing numbers, dates, or other values
- None of the above
Response: (c) Storing numerical values, dates, or other types of data
Clarification: "Storing numerical values, dates, or other types of data" is the accurate response.
152) What are the three crucial manipulations done in a "for loop" on a loop variable in JavaScript?
- The initialization, the Increment, and update
- The initialization, the test, and the update
- The initialization, the test, and Increment
- All of the above
Response: (b) The setup, the evaluation, and the increment
Clarification: "The initialization, the test, and the update" constitutes the accurate response. Within a "for loop," these three operations are essential manipulations.
153) Which of the following is the correct syntax to create a cookie using JavaScript?
- cookie = 'key1 = value1; key2 = value2; expires = date';
- cookie = 'key1 = value1; key2 = value2; expires = date';
- cookie = 'key1 = value1; key2 = value2; expires = date';
- cookie = 'key1 = value1; key2 = value2; expires = date';
Response: (a) document.cookie = 'key1=value1; key2=value2; expires=date';
Clarification: The proper syntax for setting cookies in JavaScript is document.cookie = 'key1=value1; key2=value2; expires=date'; which is the accurate response.
154) What are the different alternatives of == and != in JavaScript?
- It uses bitwise checking
- It uses === and !== instead
- It uses equals and notequals instead
- It uses equalto
Clarification: The appropriate choice is to utilize === and !== instead. In JavaScript, the operators == and != are avoided due to the type coercion they execute.
155) What are the different types of Pop up boxes available in JavaScript?
- Alert
- Prompt
- Confirm
- All of the above
Clarification: The answer that encompasses all of the previously mentioned options is indeed the correct choice.
156) Which of the following is a server-side JavaScript object?
- Date
- FileUpload
- File
- Function
Explanation: File is the correct answer.
157) What are the different types of errors in JavaScript?
- Load time errors
- Run time errors
- Logical Errors
- All of the above
Clarification: The appropriate answer is run-time errors.
158) Which of the following built-in method is used to remove the last element from an array and return that element?
- last
- pop
- get
- None of the above.
Clarification: The pop method is utilized to eliminate the final item from an array and subsequently return that item.