0% found this document useful (0 votes)
7 views

coding ans

Uploaded by

Ajun vinoraj
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

coding ans

Uploaded by

Ajun vinoraj
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

22.

function changevalue(p)

p = 5;

let a=10;

let b=5;

changevalue(b);

const result = a+"-"+b

console.log(result)
ANSWER: 10 -5

23.Given the code below:


const copy = JSON.stringify([ new String(' false '), new Bollean( false ),
undefined ]); What is the value of copy?
A. -- [ \"false\" , { } ]--

B. -- [ false, { } ]--

C. -- [ \"false\" ,false, null ]--

D. -- [ \"false\" , false, undefined ]--

ANSWER : C

24. Refer to the code below:


let sayHello = () => {
console.log ('Hello, world!');
};
Which code executes sayHello once, two minutes from now?
A. setTimeout(sayHello, 12000);

B. setInterval(sayHello, 12000);

C. setTimeout(sayHello(), 12000);

D. delay(sayHello, 12000);

ANSWER : A)setTimeout(sayHello, 12000)

25.flag();
anotherflag();

function flag(){
console.log('flag');
}
const anotherflag = () =>{
console.log('another flag');
}
What is result of the code block?
A. The console logs only 'flag'.

B. An error is thrown.

C. The console logs 'flag' and then an error is thrown.

D. The console logs 'flag' and another flag.

ANSWER: The console logs flag and then an error is thrown

26)Given the code below:


01 function GameConsole (name) {
02 this.name = name;
03 }
04
05 GameConsole.prototype.load = function(gamename) {
06 console.log( ` $(this.name) is loading a game : $(gamename) ...`);
07 )
08 function Console 16 Bit (name) {
09 GameConsole.call(this, name) ;
10 }
11 Console16bit.prototype = Object.create ( GameConsole.prototype) ;
12 //insert code here
13 console.log( ` $(this.name) is loading a cartridge game : $(gamename) ...`);
14 }
15 const console16bit = new Console16bit(' SNEGeneziz ');
16 console16bit.load(' Super Nonic 3x Force ');
What should a developer insert at line 15 to output the following message using the
method ?
> SNEGeneziz is loading a cartridge game: Super Monic 3x Force . . .
A. Console16bit.prototype.load(gamename) {

B. Console16bit.prototype.load = function(gamename) {

C. Console16bit.prototype.load(gamename) = function() {

D. Console16bit = Object.create(GameConsole.prototype).load = function


(gamename) {

Answer: option b

27.Refer to the following code that performs a basic mathematical operation on a


provided input:
function calculate(num) {
Return (num +10) / 3;
}
How should line 02 be written to ensure that x evaluates to 6 in the line below?
Let x = calculate (8);
A. Return Number(num + 10) / 3;

B. Return Integer(num +10) /3;

C. Return (Number (num +10 ) / 3;

D. Return Number((num +10) /3 );

ANSWER: Return (Number(num+10)/3 options order are differemt from out pdf
--------------------------------------------------------

7.
Let productSKU = '8675309' ;
A developer has a requirement to generate SKU numbers that are always 19 characters
lon, starting with 'sku', and padded with zeros.
Which statement assigns the values sku0000000008675309 ?

productSKU = productSKU .padStart (19. �0�).padstart(�sku�);


productSKU = productSKU .padEnd (16. �0�).padstart({�sku�);
productSKU = productSKU .padEnd (16. �0�).padstart(19, �sku�);
productSKU = productSKU .padStart (16. �0�).padstart(19, �sku�); gow

let productSKU = '8675309';


productSKU = productSKU.padStart(16, '0').padStart(19, 'sku');
console.log(productSKU)
Output : sku0000000008675309
Answer : D)productSKU = productSKU.padStart(16, '0').padStart(19, 'sku')

-----------------------------------------------------

8. what will be the output of the below?

let x= null;
console.log(typeof x)
output object

Answer : Object

----------------------------------------------------

9. At Universal Containers, every team has its own way of copying JavaScript
objects. The code
Snippet shows an implementation from one team:
function Person() {
this.firstName = "John";
this.lastName = 'Doe';
this.name =() => (
console.log('Hello $(this.firstName) $(this.firstName)')
)}
const john = new Person ();
const dan = JSON.parse(JSON.stringify(john));
dan.firstName ='Dan';
dan.name();
What is the Output of the code
execution?

TypeError: dan.name is not a function.


TypeError: Assignment to constant variable.
Hello John Doe
Hello Dan Doe
Answer: TypeError: dan.name is not a function.

--------------------------------------------------

10.let array=[1,2,3,4,4,5,4, 4];


for (let i=0; i < array.length; i++)
{
if (array[i] === 4)
{
array.splice(i,1);
}
}
console.log(array)

what is the value of the array after the code executes?


A. [1,2,3,4,5,4,4]
B. [1,2,3,4,4,5,4]
C. [1,2,3,5]
D.[1,2,3,4,5,4]

Output : [ 1, 2, 3, 4, 5, 4 ]

Answer : D

---------------------------------------------------------

20. A developer implements a function that adds a few values.


Function sum(num) {
If (num == undefined) {
Num =0;
}
Return function( num2, num3){
If (num3 === undefined) {
Num3 =0 ;
}
Return num + num2 + num3;
}
}
Which three options can the developer invoke for this function to get a return
value of 10 ?
Choose 3 answers

A. Sum (5, 5) ()

B. sum() (5, 5)

C. sum(10) ()

D. sum(5)(5)

E. Sum () (20)

Answers : C)sum()(5,5) D)sum(5)(5) there is no third choice that gives 10 in the


above options

------------------------------------------------------------

37.let o = {
get js() {
let city1 = String("st. Louis");
let city2 = String(" New York");
return {
firstCity: city1.toLowerCase(),
secondCity: city2.toLowerCase(),
}
}
}
What value can a developer expect when referencing o.js.secondCity?

console.log(o.js.secondCity)
Output : new york

ANSWER:Option: B)new york

--------------------------------------------------------------------

43. what will be the output of the below when called with an empty array?
A. Returns 0
B. Throws an error
C. Returns 10
D. Returns NaN
const myFunction = arr => {
return arr.reduce((result, current) =>{
return result = current;
}, 10); }

console.log(myFunction([]));

Output: 10
ANSWER: C.Returns 10

------------------------------------------------------------------------

50.Refer to the following array:


Let arr=[1,2, 3, 4,5];
Which three options result in x evaluating as [3, 4, 5] ?
Choose 3 answers.
A. Let x= arr.filter {{ a) => (a<2));
B. Let x= arr.splice(2,3);
C. Let x= arr.slice(2);
D. Let x= arr.filter((a) => ( return a>2));
E. Let x = arr.slice(2,3);

ANSWER: let arr=[1,2, 3, 4,5];

let a= arr.filter ((a) => (a<2));


let b= arr.splice(2,3);
let c= arr.slice(2);
let d=arr.filter((a) => {
return a>2;
});
let e = arr.slice(2,3);

console.log(a);
console.log(b);
console.log(c);
console.log(d);
console.log(e);

=====>>B,C,D

----------------------------------------------------------------------
51.Refer to code below:
Const objBook = {
Title: �Javascript�,
Object.preventExtensions(objBook); Const
newObjBook = objBook;
newObjectBook.author = �Robert�;

What are the values of objBook and newObjBook respectively ?

A. [title: �javaScript�]
title: �javaScript�]
B. {author: �Robert�, title: �javaScript} Undefined
C. {author: �Robert�, title: �javaScript}
{author: �Robert�, title: �javaScript}
D. {author: �Robert�} {author: �Robert�,
title: �javaScript}

Answer:
======

const objBook = {
title: �Javascript�,
};
Object.preventExtensions(objBook);
const newObjBook = objBook;
newObjBook.author = 'Robert';

console.log(objBook);
console.log(newObjBook)

Output:
{ title: 'Javascript' }
{ title: 'Javascript' }

------------------------------------------------------------------------

55.Refer to code below:


console.log(0);
setTimeout(({) => ( console.log(1);
}); console.log(2);
setTimeout(({) => {
console.log(3);
), 0);
console.log(4);
In which sequence will the numbers be logged?
A. 01234
B. 02431
C. 02413
D. 13024

ANSWER:
function func2(){

console.log(0);

setTimeout(() => console.log(1));

console.log(2)
setTimeout(() => console.log(3), 0);

console.log(4)
}

func2()

OUTPUT:
0
2
4
1
3

ANSWER: C)02413

62. Refer to the expression


below:
Lletx={1"+2)==(6*2);
How should this expression be modified to ensure that evaluates to false?
A. Letx=(1+' 2')==(6*2);
B. Letx=('1'+2)==(6*2);
C. Letx=(1+2)==('6'/2);
D. Letx=(1+2)==(6/2);

Answer: A due to the spce before 2

------------------------------------------------

You might also like