JavaScript MCQI. This set of questions focuses on the statements in JavaScript1) Which type of JavaScript language is ___
Answer: B Explanation: JavaScript is not a pure OOP's (object oriented programming) based languages such as PHP, java or many other languages, although it is an object-based language. It is not OOP's based language, because it doesn't have three basic properties of object-oriented programming languages, such as polymorphism, encapsulation, and inheritance. 2) Which of the following is the correct output for the following JavaScript code:
Answer: A Explanation: The output of the above snippet code will be one because, first of all, the interpreter will search "obj" for the property (y). But it fails to find "obj" for property "y," so it chooses a value from outside the object, which is available within the given code. 3) Which one of the following also known as Conditional Expression:
Answer: D Explanation: A conditional expression can only evaluate two things, which either true or false, that are purely based on the evaluation of the condition 4) Among the following given JavaScript snipped codes, which is more efficient: Code A Code B
Answer: A Explanation: Code 1 will be more efficient. In fact, the second code may encounter a runtime error because the value of "number" is never going to be equal to or less than one. 5) In JavaScript, what is a block of statement?
Answer: B Explanation: A block of statement can be understand as the set of the zero or more statements. In general, a block of statement has common definition "which combines one or a number of statements into a single statement for ease. 6) When interpreter encounters an empty statements, what it will do:
Answer: D Explanation: In JavaScript, when the interpreter encounters a empty statements it normally ignores or not response to that empty statement. The empty statements also sometimes very useful like we use the empty statements for creating loop for nothing. 7) The "function" and " var" are known as:
Answer: C Explanation: The "function" and "var" both are the Declaration statements. These both are used for defining, and declaring variable, function in anywhere in the program. 8) In the following given syntax of the switch statement, the Expression is compared with the labels using which one of the following operators?
Answer: A Explanation: The strict comparison operator returns true only if the operand are of the same type and content matches. When the switch statement is executed, the value of the expression is calculated and compared to the case labels, and looks for a case whose expressions produce the same value after evaluations (where the comparison is determined by the === operator). 9) What will happen, if the following JavaScript code is executed?
Answer: C Explanation: The function "console.log ()" used in the above function is one of the pre-defined functions of JavaScript. It takes values as arguments passed to it, and displays that value in arguments inside the console when the code is executed. 10) Which of the following is the correct output for the following JavaScript code:
Answer: C Explanation: The "if-else" is one of the conditional statements available in JavaScript like several other languages. Here the comparison performed in the "if" statement evaluates to false, so the instructions written in the else part gets executed. If the comparison performed in the "if" statement evaluates to true, then the instruction written in the if statement will be executed. 11) Which of the following is the correct output for the following JavaScript code:
Answer: C Explanation: The code of the given program uses a switch statement, in which the value of the expression is compared with the available case labels. If the value matches with any case label, the code written corresponding to that case is executed otherwise the instruction written to the default is executed. Another important point is that switch statements are also used as an alternative to "if-else" statements to reduce the complexity and size of the code. 12) Which of the following is the correct output for the following JavaScript code:
Answer: B Explanation: If we look at the given code carefully, we can see that here the "break" statement is not used after any of the case labels. Which means all the cases following "A" get executes if the following program is executed. 13) Which of the following is the correct output for the following JavaScript code:
Answer: B Explanation: The "if-and if" statement is used to examine more than one condition. This is an extension of the "if-else" statement and is also known as the "if-else ladder". We can extend the "if-else" statement to check several conditions. 14) Which of the following is the correct output for the following JavaScript code:
Answer: D Explanation: The switch case statement contains several cases in which the Default case also one of them. The default case only is get executed, when no other case matches with the expression's value. II. This set of questions focuses on the variables in JavaScript15) Which of the following variables takes precedence over the others if the names are the same?
Answer: B Explanation: In JavaScript, the local variable takes precedence over the global variable if the name of both local and global variables is the same. 16) Which one of the following is the correct way for calling the JavaScript code?
Answer: D Explanation: The JavaScript code can be called simply by making the function call to the element on which the JavaScript code execution has to be run. There are several other ways to call JavaScript code such as submit, onclick, and onload, etc. 17) Which of the following type of a variable is volatile?
Answer: A Explanation: The variables whose value can be modified that kind of variable are known as Mutable variable. In the JavaScript, only arrays and objects are mutable but not the primitive values. 18) Which of the following option is used as hexadecimal literal beginning?
Answer: D Explanation: In general, the X and x both can be used to denote the hexadecimal values, so any integer literal that begins with either 0X or 0x denotes a hexadecimal number. 19) When there is an indefinite or an infinite value during an arithmetic computation in a program, then JavaScript prints______.
Answer: C Explanation: In the case, where the result of any arithmetic expression is beyond the largest represent-able number,JavaScript prints the infinity. Similarly, if the result of any numerical operation is beyond the largest negative number, JavaScript prints negative infinity. 20) In the JavaScript, which one of the following is not considered as an error:
Answer: C Explanation: Yes, you heard right that division of any integer by zero is not an error in the JavaScript. It just prints the infinity as a result. However, there is an exception in JavaScript, dividing zero with zero will not have any defined number/value so, the result of this specific operation is a special value "Not a Number" (or NaN) and printed 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?
Answer: B Explanation: The "tofixed()" method formats the given number with a specific number of digits to the right of the decimal. 22) Which of the following number object function returns the value of the number?
Answer: B Explanation: The method " valueOf()" returns the value of the parameter that was passed in 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?
Answer: C Explanation: The method " Subtr()" in the javascript is used to return the characters in the string starting at the specified position via the specified number of the characters. 24) In JavaScript the x===y statement implies that:
Answer: C Explanation: The "===" statement are called strict comparison which only gets true only if the type and content of both the operand are strictly same. Program Output True False 25) Choose the correct snippet from the following to check if the variable "a" is not equal the "NULL":
Answer: A Explanation: The "==" is only true if the type and the content of both operands are the same. The "==" is also one of the common abstracts used for comparing two operands to check whether they are equal or not but it will notcheck the data type of the variables. So, the "! ==" operator is known as "non-equal", which is used in our case, to compare 0 to NULL. It obtains the output either as true or false that totally depends on the given 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:
Answer: D Explanation: There are three common ways to convert the text into strings:value.toString(),"" + value and String(value). We can convert a text to string without using "new" operator that are: human.tostring() and the another one is String(human). 27) See the given code of JavaScript and choose the correct output from the following:
Answer: D Explanation: The "==" operatorconverts the both operand to the same type in case they both are of different datatype and perform comparison. A strict comparison will give true as output only when the content and the data type of both operands are same. 28) What will be the output of the following JavaScript code?
Answer: A Explanation: The "===" is known as a strict comparison operator which will result as true when the data-type, content of operand are the same. For example, In JavaScript, two strings can be considered as strict equal when the length, sequence, and same characters, are the same when compared to each other. 29) Find out the correct output of the following given piece of code from the given options:
Answer: D Explanation: We can convert a non-string "integer " into a string by using the ".tostring()" method. The "===" (or we can say strict comparison) results in true only when, the content and the data-type of the operands are the same. So that's why the output of the above-given code will be obtained as true. III. This set of questions focuses on operators and expressions of JavaScript30) See the given code of JavaScript and choose the correct output from the following:
Answer: C 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. So, here the correct output would be 4050. 31) In JavaScript, what will be used for calling the function definition expression:
Answer: B Explanation: 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. 32) Which of the following one is the property of the primary expression:
Answer: D Explanation: 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. 33) Consider the following snippet of JavaScript code: Which one of the following statement is most suitable to check if the pattern matches with the sting "text".
Answer: D Explanation: The given pattern is applied on the string "text" enclosed in the parenthesis. 34) Which one of the following is used for the calling a function or a method in the JavaScript:
Answer: C Explanation: 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. 35) The "new Point(3,2)", is a kind of _______ expression
Answer: A Explanation: 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. 36) Which one of the following operator is used to check weather a specific property exists or not:
Answer: D Explanation: 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. 37) Which one of the following is an ternary operator:
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. 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_____.
Answer: D Explanation: 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. 39) Which of the following is the correct output for the following JavaScript code:
Answer: B Explanation: 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. 40) Which one of the following is correct output for the following given JavaScript code:
Answer: C Explanation: 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. 41) Which one of the following is correct output for the following given JavaScript code:
Answer: B Explanation: 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. 42) Which one of the following is correct output for the following given JavaScript code:
Answer: C Explanation: 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. 43) Which one of the following is correct output for the following given JavaScript code:
Answer: C Explanation: 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). 44) Which one of the following is correct output for the following given JavaScript code:
Answer: C Explanation: 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. 45) Which one of the following is correct output for the following given JavaScript code:
Answer: A Explanation: 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. 46) Which one of the following is correct output for the following given JavaScript code
Answer: D Explanation: 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). 47) What we will get if we compare the "one" with "8" using the less than operator ("one"<8)?
Answer: A 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:
Answer: C 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?
Answer: C 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___.
Answer: D 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.
Answer: A 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:
Answer: C 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:
Answer: D 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:
Answer: B 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 JavaScript55) Which of the following is the correct output for the following JavaScript code:
Answer: B 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: a) Code A b) Code B C) Code C d) Code D Answer: A 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?
Answer: D 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?
Answer: A 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?
Answer: D 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?
Answer: A 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?
Answer: D 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?
Answer: A 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?
Answer: C 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?
Answer: A 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?
Answer: D 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?
Answer: A 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: What is the role of the "debugger" statement?
Answer: B 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 JavaScript68) Which one of the following is the correct output for the given JavaScript code?
Answer: D 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?
Answer: C 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?
Answer: A 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?
Answer: D 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?
Answer: C 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?
Answer: B 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?
Answer: D 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______
Answer: D 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 _____.
Answer: B 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 _______.
Answer: A 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?
Answer: B 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______
Answer: D 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?
Answer: A 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_______
Answer: D 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_____
Answer: B 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 JavaScript83) What will be the output obtained by "shift ()" in the given code of JavaScript?
Answer: D 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?
Answer: C 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?
Answer: C 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?
Answer: B 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?
Answer: A 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: <script> function myFunction() { var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var myBest = fruits.slice(-3, -1); document.getElementById("demo").innerHTML = myBest; } </script> 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?
Answer: D 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 ?
Answer: D 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?
Answer: A 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?
Answer: D 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?
Answer: B 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?
Answer: C 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?
Answer: B 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:
Answer: A 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?
Answer: C 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 <script> var val1=[1,2,3]; var val2=["G,O"]; var result=val1.concat(val2); it will join values of both the array and store in the "result" variable document.writeln(result); </script> Output VII. This set of questions focuses on the functions and functional programming in JavaScript97) What is the primary role of the "return ()" statement in a function body?
Answer: D 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 _____
Answer: B 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.
Answer: A 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?
Answer: C 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 var s = function (a, b) {return a * b}; var t = s(4, 3); 101) In JavaScript, the definition of a function starts with____
Answer: A 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?
Answer: A 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?
Answer: D 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?
Answer: A 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?
Answer: B 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["x"](g,h).a["x"] > and the parenthesis will access the function "x" mentioned in it. 106) Which one of the following options is the correct output for the given code of JavaScript?
Answer: A Explanation: In JavaScript, document.write () is a predefined method which is used for printing output to the console. Here another function in the document.write () method is passed as an argument that returns the multiplication of variables a and b. 107) Which one of the following options is the correct output for the given code of JavaScript?
Answer: B Explanation: The "apply()" used in the above given code is a pre-defined method in which an array is passed as an argument and another argument passed a NULL. Here this method searches for the largest integer in the whole array. 108) Which one of the following options is the correct output for the given code of JavaScript?
Answer: A Explanation: The "bind()" function mentioned in the above-given code, is used for creating a new function which contains its own set of keywords by default. 109) Which one of the following options is the correct output for the given code of JavaScript?
Answer: A Explanation: The "call()" method mentioned in the above given piece of code, is used of calling a function in which the "this" is passed as an argument. It returns the output given by the calling function. 110) Which one of the following options is the correct output for the given code of JavaScript?
Answer: A Explanation: The "pow()" method used in the above code is one of the built-in methods which are available in the math's library of the JavaScript . This methodaccepts two arguments in which the power of the first argument is calculated with respect to the other argument. 111) Which one of the following keywords is used for defining the function in the JavaScript?
Answer: D Explanation: In JavaScript, a function is defined by using the "function" keyword along which function is named, followed by the () parenthesis. A function name can contain the dollar's signs, underscores, letters and even the digits. 112) In JavaScript, do the functions always return a value?
Answer: C Explanation: In JavaScript, a number of functions that contain a return statement usually return a value. The functions which does not have the return statement in their definition does not return any value but few of them also return value by default even if they do not contain a return statement. 113) Which one of the following codes is correct for concatenating the strings passed into the function? A. Code 1 B. Code 2 C. Code 3 D. Code 4 Answer: B Explanation: The "concat()" method is a predefined method of the JavaScript which is used for joining the two or more arrays. The significant advantage of using this method is instead of making changes in the existing array it returns a newly created array. The ".apply" method is also predefined method just like the" concat()", and it takes arrays of arguments and consider the every element of that array as an individual argument. 114) Which of the following values will be returned by the last statement in the given code?
Answer: C Explanation: The code given in the following question creates at least 10 closures, stores them as an array.Closures are all specified within the same function invocation, so they share access to the variable i.At the time of "constfun()" method returns 10 as the value of the variable i, all closures shares this value. So, all functions in a given array of functions return the exact same value. 115) What will be the correct output of the following JavaScript code?
Answer: B Explanation: The "atan2()" method used in the given code returns the arctangent of the quotient of its arguments, as the numeric values between -PI and PI radians. The returned digit represents the counterclockwise angle in radians (instead of degrees) between the positive X-axis and the point (x,y). 116) What will be the correct output of the following JavaScript code?
Answer: D Explanation: The "asinh()" method used in the given code is a predefined method available in the math's library of the JavaScript which returns the hyperbolic arcsine of a number. 117) What will happen if we execute the following code of JavaScript?
Answer: D Explanation: The function name is optional for functions defined as expressions. Function expressions are sometimes defined and implemented immediately. 118) What output will come if we run the following part of the JavaScript code?
Answer: C Explanation: The "parseIn()" is a pre-defined method of the JavaScript that parses a string, and as a result, it returns an integer. It also returns the first digit as 0 if the string does not contain an integer in the first place. 119) Which one of the given options can be considered as a code equivalent to the following code?
Answer: C Explanation: In JavaScript, as the only particular case of the "new" operator, the grammar is simplified by JavaScript by allowing the parentheses to be removed when there are no arguments passed in the function calling. So, user can neglect the empty pair of parentheses in every case of constructor invocation, in which there are no arguments. 120) If the following lines of code differ, what is the difference? Code A Code B
Answer: A Explanation: Code A will return output in the form of a "real" boolean value because we first do what is written inside the parentheses, but then negate it again immediately. Therefore, it is saying something that is not true, makes it true. Code B looks for the existence of the obj1 and obj2. Also, it may not necessarily return a "real" boolean value. This means instead of returning either true or false and it can be problematic because false-y can be either an empty string or can be 0. 121) In the following code, what value should the variable "a" contain?
Answer: C Explanation: The "counter()" method used in the above code made increment in the value of the variable by one each time it is called, and the" reset()" function resets the value of that variable to zero. Therefore if we look carefully, we can see that on variable "y" the "counter()" method was called two times, and the "reset()" method was not called even for one time, so the value of the variable y will be 2. 122) Which one of the given options can be considered as the correct output of the following code?
Answer: C Explanation: The "addition()" function was defined in the first line of code using the "new" property. In the second line of code, the addition function is called along with two passed arguments as 10, 5 inside the "document.write()" method, which prints the sum of two passed arguments returned by the "addition()" method. VIII. This set of questions focuses on the Closures in JavaScript:123) Which one of the following is not a example of closures?
Answer: A Explanation: A closure is created each time a function is created in JavaScript. In general, we can say that all the closures are function or vice versa, and function has a scope chain associated with them. 124) What output will be returned by the function in the following code?
Answer: A Explanation: Each block of code, function, or script as a whole always has an object, associated with them, called a Lexical environment. Therefore, the JavaScript code given in the above question will return the value in scope. 125) What is the primary rule of the Lexical Scoping?
Answer: D Explanation: The fundamental rule of lexical scoping is that: In the JavaScript, A function gets executed using the scope chain which was in effect, when they are defined. 126) What is required in order to implement the Lexical Scoping?
Answer: A Explanation: It is necessary to include not only that function's code in the internal state of the function's object, but also to provide references to the current scope chain. 127) Which one of the following utilize the CPU cycles in a massive manner?
Answer: D Explanation: The term "Dynamic generated graphic" refers to simulate movement, motion, or generating a specific environment using the computer. It can also be thought of as multiple plots associated with time. Hence the graphics generated in the dynamic manner from the real time data utilize the huge part of the CPU cycles. 128) In JavaScript, what kind of scoping is used?
Answer: D Explanation: In JavaScript, the lexical scoping is used just like many other modern languages.This means a function gets executed using the scope chain which was in effect, when they are defined instead of variable scope which was in effect when they are invoked/called. 129) What are the closures?
Answer: C Explanation: A closure can be referred as the set of a function's object and a scope (a group of variable bindings) in which the variables of that functions are resolved is known as the closure. 130) Which one of the following can be considered as the opposite approach of the Lexical Scoping?
Answer: A Explanation: The dynamic scoping can be considered as the opposite approach to the lexical scoping. In the dynamic scoping, it does not matter that how the code is written but what matters is how's the code executes. At the time of execution of every new function, a new scope associated with it gets pushed onto the stack and this scope normally stored along with the function call stack.At that point, when a variable is referenced in a function's definition, the scope is immediately checked in every call stack to know if it returns a value. 131) Which one of the following algorithmic languages is not the lexical scoping standardized in?
Answer: A Explanation: The Lexical scoping is Standardized in all following given algorithmic languages except the HTML. 132) What will be the output of the following JavaScript code?
Answer: D Explanation: A "constructor " is a function property of any class that is typically used for object of that class . In the above given code, both 1,2 statements are creating the instance of the class. 133) Which one of the given options can be considered as the correct output for the following JavaScript code?
Answer: C Explanation: The "object.assign()" method mentioned in the above code, is used for copying the values and properties of one object to another. Here the objects are assigned and will be copied by the reference. 134) Which of the following POSIX signals generate events?
Answer: A: "SIGINT" is the correct answer. 135) Which HTML element is used to put the JavaScript code?
Answer: D: "<script>" is the correct answer. 136) Which of the following statement is not correct in the case of JavaScript?
Answer: B: JavaScript is a high-level programming language. 137) Why is JavaScript called a structured programming language?
Answer: C: "Because it follows the syntax and structure of the C programming language which is a structured programming language," is the correct answer. 138) Which of the following is the correct syntax to print a page using JavaScript?
Answer: B: "window.print(); " is the correct answer. 139) Which of the following is not a JavaScript Data Types?
Answer: D: "Float" is the correct answer. JavaScript supports only the following Data types: 140) Which of the following is the correct JavaScript syntax to access the element using HTML code?
Answer: document.getElementById ("availablecourse").innerHTML = "See the list of availablecourse"; is the correct answer. To access the content written under that id, we have to use the.innerHTML to specify that and finally replace the content with whatever is written inside the quotes. 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?
Answer: B: "unshift()" is the correct answer. It is used to add one or more elements to the front of an array and returns the new length of the array. 142) Which of the following syntax is correct to refer to an external script called "LFC.js"?
Answer: C: <script src="LFC.js"> is the correct answer. The "src" is used to refer to any JavaScript file. 143) Which of the following syntax can be used to write "Hello World" in an alert box?
Answer: C: "alert("Hello World");" is the correct answer. 144) Which of the following is not a JavaScript framework or library?
Answer: D: "Cassandra" is the correct answer. It is not a JavaScript framework or library. It is a distributed database from Apache. 145) Why does the name of JavaScript and Java are similar?
Answer: B: "The syntax of JavaScript is loosely based on the syntax of Java" is the correct answer. 146) Which of the following is the correct statement of WHILE loop start?
Answer: A: "while (i <= 10)" is the correct answer. 147) What was the original name of JavaScript when it discovered?
Answer: D: "Mocha" is the correct answer. When JavaScript was discovered, it was initially called Mocha, then renamed to LiveScript, and finally to JavaScript when Netscape and Sun did a license agreement. It was named JavaScript because, at that time, it was made as a scripting language complementary to Java. 148) Which of the following is the correct way to write a comment in JavaScript code?
Answer: A: //This is a comment is the correct option. 149) What would be the output of the following Javascript code?
Answer: C: Fee10000 is the correct answer. After concatenation, both the strings are shown as a concatenated string. 150) Which of the following JavaScript operator is used to assign a value to a variable based on some condition?
Answer: C: Conditional operator is the correct answer. 151) Which of the following variables are used in JavaScript programs?
Answer: C: "Storing numbers, dates, or other values" is the correct answer. 152) What are the three crucial manipulations done in a "for loop" on a loop variable in JavaScript?
Answer: B: "The initialization, the test, and the update" is the correct answer. In a "for loop", these three are very crucial manipulations. 153) Which of the following is the correct syntax to create a cookie using JavaScript?
Answer: A: document.cookie = 'key1 = value1; key2 = value2; expires = date'; is the correct answer. 154) What are the different alternatives of == and != in JavaScript?
Answer: B: It uses === and !== instead is the correct answer. In JavaScript, the == and != operator are not used because of the type conversion they perform. 155) What are the different types of Pop up boxes available in JavaScript?
Answer: D: "All of the above" is the correct answer. 156) Which of the following is a server-side JavaScript object?
Answer: C: File is the correct answer. 157) What are the different types of errors in JavaScript?
Answer: B: 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?
Answer: B: The pop() method is the correct answer. It is used to remove the last element from an array and return that element. Next TopicJavaScript Interview Questions |