Home
Current Affairs January 2024

What is the correct answer?

4

What will be the shift() output of the following JavaScript code?
var a = [];
a.unshift(1);
a.unshift(22);
a.shift();
a.unshift(3,[4,5]);
a.shift();
a.shift();
a.shift();

A. 1

B. [4,5]

C. [3,4,5]

D. Exception is thrown

Correct Answer :

A. 1


Explanation: The unshift() and shift() methods behave much like push() and pop(), except that they insert and remove elements from the beginning of an array rather than from the end. unshift() adds an element or elements to the beginning of the array, shifts the existing array elements up to higher indexes to make room, and returns the new length of the array. shift() removes and returns the first element of the array, shifting all subsequent elements down one place to occupy the newly vacant space at the start of the array.

Related Questions

What is the correct answer?

4

JavaScript Code can be called by using ___________

A. RMI

B. Triggering Event

C. Preprocessor

D. Function/Method

What is the correct answer?

4

What is the observation made in the following JavaScript code?
var count = [1,,3];

A. The omitted value takes undefined

B. This results in an error

C. This results in an exception

D. The omitted value takes an integer value

What is the correct answer?

4

The pop() method of the array does which of the following task?

A. decrements the total length by 1

B. increments the total length by 1

C. prints the first element but no effect on the length

D. updates the element

What is the correct answer?

4

What will be the equivalent code of the following JavaScript code?
o.m(x,y);

A. o.m(x) && o.m(y);

B. o[m](x,y);

C. o(m)[x,y];

D. o.m(x && y);

What is the correct answer?

4

Consider the following code snippet.
while (a != 0)
{
if (a == 1)
continue;
else
a++;
}

What will be the role of the continue keyword in the above code snippet?

A. The continue keyword restarts the loop

B. The continue keyword skips the next iteration

C. The continue keyword skips the rest of the statements in that iteration

D. The continue keyword breaks out of the loop

What is the correct answer?

4

What will be the output of the following JavaScript code?
var grade='A';
var result;
switch(grade)
{
case 'A':
result+=10;
case 'B':
result+= 9;
case 'C':
result+= 8;
default:
result+= 0;
}
document.write(result);

A. 10

B. 27

C. 8

D. 0

What is the correct answer?

4

What will be the output of the following Javascript code?
var a= 0;
var b = 0;
while (a < 3)
{
a++;
b += a;
console.log(b);
}

A. 135

B. 123

C. 013

D. 01

What is the correct answer?

4

What will be the output of the following JavaScript code?
var obj=
{
length:20,
height:35,
}
if (breadth' in obj === false)
{
obj.breadth = 12;
}
console.log(obj.breadth);

A. 20

B. 12

C. undefined

D. error

What is the correct answer?

4

What will be the output of the following Javascript code?
<script>
var x = 5;
var y = 2;
var z = x % y;
document.getElementById("demo").innerHTML = z;
</script>


A. 0

B. 1

C. 2

D. 5

What is the correct answer?

4

What will be the output of the following JavaScript code?
const object1 = {};
a = Symbol('a');
b = Symbol.for('b');
object1[a] = 'harry';
object1[b] = 'derry';
const objectSymbols = Object.getOwnPropertySymbols(object1);
console.log(objectSymbols.length);

A. 0

B. 2

C. 1

D. Error

What is the correct answer?

4

Consider the following code snippet
function f(o)
{
if (o === undefined) debugger;
}

What could be the task of the statement debugger?

A. It does nothing but a simple breakpoint

B. It debugs the error in that statement and restarts the statements execution

C. It is used as a keyword that debugs the entire program at once

D. It is used to find error in the statement

What is the correct answer?

4

What will be the output of the following JavaScript code?
int sum=0;
var arr = [10,15,20,30];
arr.forEach(function myFunction(element)
{
sum= sum+element;
});
document.writeln(sum);

A. 70

B. 75

C. 10

D. error

What is the correct answer?

4

The generalised syntax for a real number representation is __________

A. [digits][.digits][(E|e)[(+|-)]digits]

B. [digits][+digits][(E|e)[(+|-)]digits]

C. [digits][(E|e)[(+|-)]digits]

D. [.digits][digits][(E|e)[(+|-)]digits]

What is the correct answer?

4

What will be the step of the interpreter in a jump statement when an exception is thrown?

A. The interpreter stops its work

B. The interpreter throws another exception

C. The interpreter jumps to the nearest enclosing exception handler

D. The interpreter throws an error

What is the correct answer?

4

Which is an equivalent code to invoke a function m of class o that expects two arguments x and y?

A. o(x,y);

B. o.m(x) && o.m(y);

C. m(x,y);

D. o.m(x,y);

What is the correct answer?

4

What will be the output of the following JavaScript code?
Int a=1;
if(a>10)
{
document.write(10);
}
else
{
document.write(a);
}

A. 10

B. 0

C. 1

D. Undefined

What is the correct answer?

4

The enumeration order becomes implementation dependent and non-interoperable if ___________

A. If the object inherits enumerable properties

B. The object does not have the properties present in the integer array indices

C. The delete keyword is never used

D. Object.defineProperty() is not used

What is the correct answer?

4

The primary purpose of the array map() function is that it __________

A. maps the elements of another array into itself

B. passes each element of the array and returns the necessary mapped elements

C. passes each 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

D. pass the elements of the array into another array

What is the correct answer?

4

What will happen if the body of a for/in loop deletes a property that has not yet been enumerated?

A. The property will be stored in a cache

B. The loop will not run

C. That property will not be enumerated

D. The property will be enumerated

What is the correct answer?

4

What is the difference between the two lines given below ?
!!(obj1 && obj2);
(obj1 && obj2);

A. Both the lines result in a boolean value True

B. Both the lines result in a boolean value False

C. Both the lines checks just for the existence of the object alone

D. The first line results in a real boolean value whereas the second line merely checks for the existence of the objects

What is the correct answer?

4

The purpose of extensible attribute is to __________

A. make all of the own properties of that object non configurable

B. to configure and bring a writable property

C. lock down objects into a known state and prevent outside tampering

D. to include new properties into the object

What is the correct answer?

4

Which keyword is used to define the function in javascript?

A. void

B. int

C. function

D. main

What is the correct answer?

4

What kind of expression is new Point(2,3)?

A. Primary Expression

B. Object Creation Expression

C. Invocation Expression

D. Constructor Calling Expression

What is the correct answer?

4

JavaScript can be written __________

A. directly into JS file and included into HTML

B. directly on the server page

C. directly into HTML pages

D. directly into the css file

What is the correct answer?

4

One of the special feature of an interpreter in reference with the for loop is that ___________

A. Before each iteration, the interpreter evaluates the variable expression and assigns the name of the property

B. The iterations can be infinite when an interpreter is used

C. The body of the loop is executed only once

D. the iteration is finite when an interpreter is used

What is the correct answer?

4

The method or operator used to identify the array is __________

A. isarrayType()

B. ==

C. ===

D. typeof

What is the correct answer?

4

Which of the following is not considered as an error in JavaScript?

A. Syntax error

B. Missing of semicolons

C. Division by zero

D. Missing of Bracket

What is the correct answer?

4

Consider the following code snippet :
var c = counter(), d = counter();
c.count()
d.count()
c.reset()
c.count()
d.count()

The state stored in d is :

A. 1

B. 0

C. Null

D. Undefined

What is the correct answer?

4

The snippet that has to be used to check if a is not equal to null is _________

A. if(a!=null)

B. if (!a)

C. if(a!null)

D. if(a!==null)

What is the correct answer?

4

What is the purpose of a return statement in a function?

A. Returns the value and continues executing rest of the statements, if any

B. Returns the value and stops the program

C. Returns the value and stops executing the function

D. Stops executing the function and returns the value