Which one of the following options is the correct output for the given code of javascript

I. This set of questions focuses on the statements in JavaScript

1] Which type of JavaScript language is ___

  1. Object-Oriented
  2. Object-Based
  3. Assembly-language
  4. High-level

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:

  1. 1
  2. Error
  3. 10
  4. 5

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:

  1. Alternative to if-else
  2. Switch statement
  3. If-then-else statement
  4. immediate if

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

  1. Code 1
  2. Code 2
  3. Both Code 1 and Code 2
  4. Cannot Compare

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?

  1. Conditional block
  2. block that combines a number of statements into a single compound statement
  3. both conditional block and a single statement
  4. block that contains a single 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:

  1. Shows a warning
  2. Prompts to complete the statement
  3. Throws an error
  4. Ignores the statements

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:

  1. Keywords
  2. Data types
  3. Declaration statements
  4. Prototypes

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?

  1. ===
  2. equals
  3. ==
  4. equals

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?

  1. An error is displayed
  2. An exception is thrown
  3. The values of count variable are logged or stored in a particular location or storage
  4. The value of count from 0 to 9 is displayed in the console

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:

  1. 9
  2. 0
  3. 8
  4. Undefined

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:

  1. 10
  2. 9
  3. 8
  4. 0

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:

  1. 10
  2. 6
  3. 33
  4. 0

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:

  1. 3
  2. 0
  3. Error
  4. 2

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:

  1. 10
  2. 17
  3. 18
  4. 0

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 JavaScript

15] Which of the following variables takes precedence over the others if the names are the same?

  1. Global variable
  2. The local element
  3. The two of the above
  4. None of the above

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?

  1. Preprocessor
  2. Triggering Event
  3. RMI
  4. Function/Method

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, title, and onload, etc.

17] Which of the following type of a variable is volatile?

  1. Mutable variable
  2. Dynamic variable
  3. Volatile variable
  4. Immutable variable

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?

  1. 00
  2. 0x
  3. 0X
  4. Both 0x and 0X

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______.

  1. Prints an exception error
  2. Prints an overflow error
  3. Displays "Infinity"
  4. Prints the value as such

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:

  1. Syntax error
  2. Missing of semicolons
  3. Division by zero
  4. Missing of Bracket

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?

  1. toExponential[]
  2. toFixed[]
  3. toPrecision[]
  4. toLocaleString[]

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?

  1. toString[]
  2. valueOf[]
  3. toLocaleString[]
  4. toPrecision[]

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?

  1. slice[]
  2. split[]
  3. substr[]
  4. search[]

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:

  1. Both x and y are equal in value, type and reference address as well.
  2. Both are x and y are equal in value only.
  3. Both are equal in the value and data type.
  4. Both are not same at all.

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

25] Choose the correct snippet from the following to check if the variable "a" is not equal the "NULL":

  1. if[a!==null]
  2. if [a!]
  3. if[a!null]
  4. if[a!=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:

  1. toString[]
  2. String[human]
  3. String newvariable="human"
  4. Both human.toString[] and String[human]

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:

  1. compilation error
  2. false
  3. runtime error
  4. true

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?

  1. True
  2. false
  3. runtime error
  4. compilation error

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:

  1. logical error
  2. false
  3. runtime error
  4. true

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 JavaScript

30] See the given code of JavaScript and choose the correct output from the following:

  1. 4090
  2. 90
  3. 4050
  4. Exception

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:

  1. Function prototype
  2. Function literal
  3. Function calling
  4. Function declaration

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:

  1. Contains only keywords
  2. basic expressions containing all necessary functions
  3. contains variable references alone
  4. stand-alone expressions

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".

  1. test[text]
  2. equals[pattern]
  3. test[pattern]
  4. text==pattern

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:

  1. Property Access Expression
  2. Functional expression
  3. Invocation expression
  4. Primary expression

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

  1. Object Creation Expression
  2. Primary Expression
  3. Invocation Expression
  4. Constructor Calling 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:

  1. Exists
  2. exist
  3. within
  4. in

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:

  1. ?
  2. :
  3. -
  4. +

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_____.

  1. Properties
  2. Prototypes
  3. Definition
  4. Lvalue

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:

  1. False
  2. True
  3. Runtime error
  4. Compilation error

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:

  1. Error
  2. Undefined
  3. 12
  4. 20

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:

  1. 123.56
  2. Taller
  3. 190
  4. Little shorter

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:

  1. Good
  2. Evening
  3. GooodEvening
  4. undefined

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:

  1. Error
  2. clean:Italy
  3. clean:India
  4. undefined

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:

  1. 7
  2. -7.25
  3. 25
  4. -7

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:

  1. 972
  2. 81
  3. 9
  4. Error

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

  1. 01
  2. 4
  3. 00
  4. 047

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"

Chủ Đề