JavaScript is a versatile language for building interactive web applications. It runs in the browser and enables real-time updates and user interactivity.
Last updated on:- 3rd June 2023
1.
JavaScript is an _____________ language.
Object-oriented
Object-based
Object-referred
Assembly
For any programming language to be classified as object-oriented, it must have proper characteristics of an object-oriented programming language, such as polymorphism, encapsulation, inheritance, etc. And JavaScript does not have that. However, JavaScript does treat objects like data structures, hence it classifies as object-based.
2.
Which of the following is the main entry point to all client-side JavaScript features and APIs ?
Window
Location
Standard
Position
All client-side JavaScript features and APIs are accessed through the Window object. It represents a web browser's window or frame, and the identifier Window can be used to refer to it.
3.
What is hoisting in JavaScript ?
A way to move variables and functions to the top of their respective scopes
A way to remove variables and functions from their respective scopes
A way to convert variables and functions to a different data type
A way to prevent variables and functions from being used
Hoisting in JavaScript is the behavior of moving variables and function declarations to the top of their respective scopes (either the global scope or the local scope of a function). JavaScript Hoisting refers to the process whereby the interpreter appears to move the declaration of functions, variables ( let and const excluded ) or classes to the top of their scope, prior to execution of the code.
4.
What are closures in JavaScript ?
A function that is enclosed with references to its inner function scope
A function that is enclosed with references to its lexical environment
A function that is enclosed with the object to its inner function scope
None of the mentioned
A closure is a function that is enclosed with references to its lexical environment. A closure allows an inner function to access the scope of an outside function. Closures are formed every time a function is created in JavaScript, during function creation time.
5.
What does the interpreter do when it encounters an empty statement ?
Shows a warning
Prompts to complete the statement
Ignores the statement
Throws an error
In JavaScript, when the interpreter encounters an empty statement, it normally ignores or does not respond to that empty statement. The empty statement is sometimes useful, such as for creating loops for nothing.
6.
Arrays in JavaScript are defined by which of the following statements ?
It is an ordered list of values
It is an ordered list of functions
It is an ordered list of strings
It is an ordered list of objects
An array in JavaScript is an ordered list of values, each value is referred to as an element, and it is identified by an index. An array can include values of many sorts, and the length of an array is dynamically sized.
7.
Which of the following scoping type does JavaScript use ?
Sequential
Lexical
Segmental
Literal
JavaScript, like most current programming languages, uses lexical scoping. This means that functions are performed with the variable scope in effect when they were defined, rather than the variable scope in effect when they are invoked.
8.
What is the basic factor that differentiates JavaScript from Java ?
There is no difference
Variables are specific
Functions are considered as fields
Functions are values, and there is no hard distinction between methods and fields
Functions in JavaScript are values, while methods and fields are not clearly defined.
9.
Which of the following variables takes precedence over the others if the names are the same ?
The local element
Global variable
Both of the above
None of the above
In JavaScript, the local variable takes precedence over the global variable if nameS of both the local and global variables are same.
10.
Why is a JavaScript engine needed ?
Interpreting the JavaScript
Compiling the JavaScript
Both compiling and interpreting JavaScript
Parsing the JavaScript
The JavaScript engine is used to interpret JavaScript and run it on a web page.
11.
Which of the following methods can be used to add new elements to an array ?
push()
unshift()
splice()
All of the above
All of the mentioned methods: push(), unshift(), and splice() can be used to add new elements to an array in JavaScript.
12.
Which of the following methods is used to remove the first element from an array ?
splice()
pop()
shift()
slice()
The shift() method is used to remove the first element from an array and shift all other elements down by one position.
13.
In JavaScript, which one of the following is not considered as an error ?
Division by zero
Syntax error
Missing of semicolons
Missing of Bracket
Division by zero in JavaScript does not throw an error. It returns a special value: 'Infinity', when dividing a number by zero. However, dividing zero by zero will result in 'NaN' ( Not a Number ).
14.
Which of the following method returns the value of the number ?
toString()
toLocaleString()
toPrecision()
valueOf()
The valueOf() method is used to return the primitive value of a Number object.
15.
Which of the following methods returns the character in the string starting at the specified position via the specified number of characters ?
slice()
search()
split()
substr()
The substr() method is used to extract a substring from a string, starting at a specified position and with a specified number of characters.
16.
In JavaScript, the x===y statement implies that:
Both are equal in value, type and reference address as well
Both are equal in value only
Both are equal in value and data type
Both are not the same at all
The '===' (strict equality ) operator in JavaScript checks if both the value and data type of the operands are equal.
17.
What task is performed by the pop() method of an array ?
It updates the elements of array
It increments the total length of array by 1
It prints the first element and has no impact on the length of array
It removes one element from the end of array
The pop() method of an array removes the last element from the array and returns that element.
18.
Which one of the following is used for calling a function or a method in JavaScript ?
Property Access Expression
Functional expression
Invocation expression
Primary expression
The invocation expression is used to call a function or a method in JavaScript.
19.
Which one of the following operators is used to check whether a specific property exists or not ?
Exists
Exist
Within
In
The 'in' operator is used to check if a specific property exists.
20.
Which one of the following is a ternary operator?
?
:
-
+
The '?' symbol is the conditional (ternary) operator in JavaScript. It combines three expressions into one.
21.
What will be the result of: 'one' < 8 ?
True
False
NaN
Undefined
When comparing a string with a number using the less than operator ('<'), JavaScript converts the string to a numeric value. Since 'one' cannot be converted to a number, it is treated as NaN, which is not less than 8, resulting in 'false'.
22.
Which one of the following is known as the Equality operator, and is used to check whether the two values are equal or not ?
=
===
==
&&
The '==' operator in JavaScript is known as the Equality operator. It checks whether the values of two operands are equal or not, performing type coercion if necessary.
23.
Which one of the following operators returns false if both values are equal ?
!
!==
!=
All of the above
The '!=' operator in JavaScript returns 'false' if the two values are equal. If you're asked to also compare data types, then the answer would be '!=='.
24.
In a case where the value of the operand is NULL, the typeof returned by the unary operator is _________.
undefined
string
boolean
object
When the value of an operand is null, the 'typeof' of the unary operator returns 'object'.
25.
Which one of the following is not a keyword ?
if
with
use strict
debugger
The 'use strict' is not a keyword but a directive introduced in ECMAScript 5.
26.
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
The three important manipulations for a loop on a loop variable are Initialization, Testing, and Updation.
27.
Which one of the following is not considered as a 'statement' in JavaScript ?
use strict
debugger
if
with
The 'use strict' directive is not considered as a statement because it does not include any language keywords.
28.
What happens if we define a 'for' loop and it removes one of the properties that have 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
If a property is removed during the execution of a 'for' loop and that property has not yet been enumerated, it will not be enumerated.
29.
What is the correct response by the interpreter in a jump statement when an exception is thrown ?
The interpreter will jump to the nearest enclosing exception handler
The interpreter will throw another exception
The interpreter will stop working
The interpreter throws an error
When an exception is thrown, the interpreter jumps to the nearest enclosing exception handler, if one exists.
30.
A set of unordered properties that has a name and value is called ________
String
Array
Serialized Object
Object
An object in JavaScript is a set of unordered properties, each having a name and value.