How to pass Javascript Linkedin Test Question and Answers

 Javascript Linkedin Test Question and Answers 



Q1. Which of the following type of variable is visible everywhere in your JavaScript code?


global variable

local variable

Both of the above.

None of the above.


Q2. Which built-in method returns the length of the string?


length()

size()

index()

None of the above.


Q3. Which of the following code creates an object?


var book = Object();

var book = new Object();

var book = new OBJECT();

var book = new Book();


Q4. Which of the following function of String object combines the text of two strings and returns a new string?


add()

merge()

concat()

append()


Q5. Which of the following function of String object executes the search for a match between a regular expression and a specified string?


concat()

match()

replace()

search()


Q6. Which of the following function of String object creates a string to be displayed in a big font as if it were in a <big> tag?


anchor()

big()

blink()

italics()


Q7. Which of the following function of String object causes a string to be displayed in the specified size as if it were in a <font size = 'size'> tag?


fixed()

fontcolor()

fontsize()

bold()


Q8. Which of the following function of Array object returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found?


indexOf()

join()

lastIndexOf()

map()


Q9. Which of the following function of Array object reverses the order of the elements of an array?


reverse()

push()

reduce()

reduceRight()


Q10. What will be the return type of a method that not returns any value?.


void

int

double

None of the above


Q11. Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?


blur

focus

hover

enter


Q12. What is the result in the console of running this code?


function logThis() {

  console.log(this);

}

logThis();


function

undefined

Function.prototype

window


Q13. Which class-based component is equivalent to this function component?


const Greeting = ({ name }) => <h1>Hello {name}!</h1>;


class Greeting extends React.Component { constructor() { return <h1>Hello {this.props.name}!</h1>; } }

class Greeting extends React.Component { <h>Hello {this.props.name}!</h>; } }

class Greeting extends React.Component { render({ name }) { return <h1>Hello {name}!</h1>; } }

class Greeting extends React.Component { render() { return <h1>Hello {this.props.name}!</h1>; } }


Q14. Which class-based lifecycle method would be called at the same time as this effect Hook?


useEffect(() => {

  // do things

}, []);


componentWillUnmount

componentDidUpdate

render

componentDidMount


Q15. What is the output of this code?


var obj;

console.log(obj);


ReferenceError: obj is not defined

{}

undefined

null



Q16. What is wrong with this code?


const foo = {

  bar() {

    console.log('Hello, world!');

  },

  name: 'Albert',

  age: 26,

};


The function bar needs to be defined as a key/value pair.

Trailing commas are not allowed in JavaScript.

Functions cannot be declared as properties of objects.

Nothing, there are no errors.


Q17. What will this code log to the console?


const foo = [1, 2, 3];

const [n] = foo;

console.log(n);


1

undefined

NaN

Nothing--this is not proper JavaScript syntax and will throw an error.


Q18. How do you remove the property name from this object?

const foo = {

  name: 'Albert',

};


delete name from foo;

delete foo.name;

del foo.name;

remove foo.name;


Q19. What is the difference between the map() and the forEach() methods on the Array prototype?


The map() methods returns a new array with a transformation applied on each item in the original array, wheras the forEach() method iterates through an array with noreturn value.

There is no difference.

The forEach() method returns a single output value, wheras the map() method performs operation on each value in the array.

The forEach() methods returns a new array with a transformation applied on each item in the original array, wheras the map() method iterates through an array with noreturn value.


Q20. Which concept is defined as a template that can be used to generate different objects that share some shape and/or behavior?


class

generator function

map

proxy


Q21. How do you add a comment to JavaScript code?


! This is a comment

// This is a comment

# This is a comment

\\ This is a comment


Q22. If you attempt to call a value as a function but the value is not a function, what kind of error would you get?


TypeError

SystemError

SyntaxError

LogicError


Q23. Which method is called automatically when an object is initialized?


create()

new()

constructor()

init()


Q24. What is the result of running the statement shown?

let a = 5;

console.log(++a);


6

10

5

4


Q25. You've written the event listener shown below for a form button, but each time you click the button, the page reloads. Which statement would stop this from happening?

button.addEventListener(

  'click',

  function (e) {

    button.className = 'clicked';

  },

  false,

);


e.blockReload();

button.preventDefault();

button.blockReload();

e.preventDefault();


Q26. Which statement represents the starting code converted to an IIFE?


function() { console.log('lorem ipsum'); }()();

(function() { console.log('lorem ipsum'); })();

function() { console.log('lorem ipsum'); }();


Q27. Which statement selects all img elements in the DOM tree?


Document.querySelector('img')

Document.querySelectorAll('<img>')

Document.querySelectorAll('img')

Document.querySelector('<img>')


Q28. Why would you choose an asynchronous structure for your code?


To use ES6 syntax

To start tasks that might take some time without blocking subsequent tasks from executing immediately

To ensure that parsers enforce all JavaScript syntax rules when processing your code

To ensure that tasks further down in your code aren't initiated until earlier tasks have completed


Q29. What is the HTTP verb to request the contents of an existing resource?


PATCH

POST

DELETE

GET


Q30. How does the forEach() method differ from a for statement?


forEach can be used only with an array, whereas for can be used with additional data types.

forEach allows you to specify your own iterator, whereas for does not.

forEach can be used only with strings, whereas for can be used with additional data types.

for loops can be nested; whereas forEach loops cannot.


Q31. Which choice is an incorrect way to define an arrow function that returns an empty object?


=> ({})

=> {}

=> { return {};}

=> (({}))


Q32. Why might you choose to make your code asynchronous?


to start tasks that might take some time without blocking subsequent tasks from executing immediately

to ensure that tasks further down in your code are not initiated until earlier tasks have completed

to make your code faster

to ensure that the call stack maintains a LIFO (Last in, First Out) structure


Q33. Which expression evaluates to true?


[3] == [3]

3 == '3'

3 != '3'

3 === '3'


Q34. Which of these is a valid variable name?


5thItem

firstName

grand total

function


Q35. Which method cancels event default behavior?


cancel()

stop()

prevent()

preventDefault()


Q36. Which method do you use to attach one DOM node to another?


attachNode()

getNode()

querySelector()

appendChild()


Q37. Which statement is used to skip iteration of the loop?


break

pass

skip

continue


Q38. Which choice is valid example for an arrow function?


a, b => {return c;}

a, b => c

(a,b) => c

{ a, b } => c


Q39. Which operator returns true if the two compared values are not equal?


<>

!==

~

==!



Q40. How is a forEach statement different from a for statement?


A for statement is generic, but a for Each statement can be used only with an array.

Only a forEach statement lets you specify your own iterator.

A forEach statement is generic, but a for statement can be used only with an array.

Only a for statement uses a callback function.


Q41. How would you use this function to find out how much tax should be paid on $50?

function addTax(total) {

  return total * 1.05;

}


addTax(50);

addTax 50;

addTax = 50;

return addTax 50;


Q42. Which statement is the correct way to create a variable called rate and assign it the value 100?


let 100 = rate;

100 = let rate;

let rate = 100;

rate = 100;


Q43. Which statement creates a new object using the Person constructor?


var student = construct Person;

var student = Person();

var student = new Person();

var student = construct Person();


Q44. When would the final statement in the code shown be logged to the console?


let modal = document.querySelector('#result');

setTimeout(function(){

    modal.classList.remove('hidden);

}, 10000);

console.log('Results shown');


after 10 second

after results are received from the HTTP request

after 10000 seconds

immediately


Q45. When would 'results shown' be logged to the console?


let modal = document.querySelector('#results');

setTimeout(function () {

  modal.classList.remove('hidden');

}, 10000);


after results are received from the HTTP request

after 10 second

immediately

after 10,000 seconds


Q46. You've written the code shown to log a set of consecutive values, but it instead results in the value 5, 5, 5, and 5 being logged to the console. Which revised version of the code would result in the value 1, 2, 3 and 4 being logged?


for (var i = 1; i <= 4; i++) {

  setTimeout(function () {

    console.log(i);

  }, i * 10000);

}



for (var i = 1; i <= 4; i++) {

  (function (i) {

    setTimeout(function () {

      console.log(j);

    }, j * 1000);

  })(j);

}



while (var i=1; i<=4; i++) {

  setTimeout(function() {

    console.log(i);

    }, i*1000);

}




for (var j = 1; j <= 4; j++) {

  setTimeout(function () {

    console.log(j);

  }, j * 1000);

}


for (var i = 1; i <= 4; i++) {

  (function (j) {

    setTimeout(function () {

      console.log(j);

    }, j * 1000);

  })(i);

}



Q47. How does a function create a closure?


It reloads the document whenever the value changes.

It completes execution without returning.

It copies a local variable to the global scope.

It returns a reference to a variable in its parent scope.


Q48. Which statement creates a new function called discountPrice?


let discountPrice = function (price) {

  return price * 0.85;

};



let discountPrice(price) {

  return price * 0.85;

};


let function = discountPrice(price) {

  return price * 0.85;

};


discountPrice = function (price) {

  return price * 0.85;

};



Q49. What will the value of y be in this code:

const x = 6 % 2;

const y = x ? 'One' : 'Two';


One

Two

undefined

TRUE



Q50. Which keyword is used to create an error?


throw

exception

catch

error


Q51. What's one difference between the async and defer attributes of the HTML script tag?


The defer attribute works only with promises.

The defer attribute will asynchronously load the scripts in order.


The defer attribute can work synchronously.

The defer attribute works only with generators.


Q52. The following program has a problem. What is it?


var a;

var b = (a = 3) ? true : false;


The condition in the ternary is using the assignment operator.

You can't define a variable without initializing it.

You can't use a ternary in the right-hand side of an assignment operator.

The code is using the deprecated var keyword.


Q53. Which statement references the DOM node created by the code shown?

<p class="pull">lorem ipsum</p>


Document.querySelector('pull')

Document.querySelector('#pull')

Document.querySelector('class.pull')

document.querySelector('.pull');


Q54. What value does this code return?


let answer = true;

if (answer === false) {

  return 0;

} else {

  return 10;

}


0

true

false

10


Q55. What is the result in the console of running the code shown?

var start = 1;

function setEnd() {

  var end = 10;

}

setEnd();

console.log(end);


10

0

ReferenceError

undefined


Q56. What will this code log in the console?


function sayHello() {

  console.log('hello');

}

console.log(sayHello.prototype);


undefined

an object with a constructor property

"hello"

an error message


Q57. Which collection object allows unique value to be inserted only once?


Object

Set

Array

Map


Q58. What two values will this code print?

function printA() {

  console.log(answer);

  var answer = 1;

}

printA();

printA();


1 then 1

1 then undefined

undefined then undefined

undefined then 1


Q59. Which of the following values is not a Boolean false?


Boolean(0)

Boolean("")

Boolean(NaN)

Boolean("false")


Q60. Which of the following is not a keyword in JavaScript?


this

Array

catch

function


Q61. Which variable is an implicit parameter for every function in JavaScript?


Arguments

args

argsArray

argumentsList


Q62. For the following class, how do you get the value of 42 from an instance of X?


class X {

  get Y() {

    return 42;

  }

}


x.get('Y')

x.Y

x.Y()

x.get().Y


Q63. What is the result of running this code?


sum(10, 20);

diff(10, 20);

function sum(x, y) {

  return x + y;

}


let diff = function (x, y) {

  return x - y;

};


30, ReferenceError

30, ReferenceError, 30, -10

30, -10

ReferenceError, -10


Q64. Why is it usually better to work with Objects instead of Arrays to store a collection of records?


Objects are more efficient in terms of storage.

Adding a record to an object is significantly faster than pushing a record into an array.

Most operations involve looking up a record, and objects can do that better than arrays.

Working with objects makes the code more readable.


Q65. Which statement is true about the "async" attribute for the HTML script tag?


It can be used only for external JavaScript code.

It can be used for both internal and external JavaScript code.

It can be used only for internal JavaScript code.

It can be used only for internal or external JavaScript code that exports a promise.


Q66. How do you import the lodash library making it top-level Api available as the "_" variable?


import _ from 'lodash';

import 'lodash' as _;

import '_' from 'lodash;

import lodash as _ from 'lodash';


Q67. What does the following expression evaluate to?

[] == [];


True

undefined

[]

False


Q68. What is the name of a function whose execution can be suspended and resumed at a later point?


Generator function

Arrow function

Async/ Await function

Promise function


Q69. What will this code print?

var v = 1;

var f1 = function () {

  console.log(v);

};


var f2 = function () {

  var v = 2;

  f1();

};


f2();


1

2

Nothing - this code will throw an error.

undefined


Q70. Which statement is true about Functional Programming?


Every object in the program has to be a function.

Code is grouped with the state it modifies.

Date fields and methods are kept in units.

Side effects are not allowed.


Q71. Your code is producing the error: TypeError: Cannot read property 'reduce' of undefined. What does that mean?

You are calling a method named reduce on an object that does not exist.

You are calling a method named reduce on an empty array.

You are calling a method named reduce on an object that's has a null value.

You are calling a method named reduce on an object that's declared but has no value.


Q72. How many prototype objects are in the chain for the following array?

let arr = [];


0

1

2

3


Q73. Which choice is not a unary operator?


typeof

delete

instanceof

void


Q74. What type of scope does the end variable have in the code shown?

var start = 1;

if (start === 1) {

  let end = 2;

}


conditional

block

global

function


Q75. What would be the result in the console of running this code?

for (var i = 0; i < 5; i++) {

  console.log(i);

}


12345

1234

01234

012345


Q76. Which Object method returns an iterable that can be used to iterate over the properties of an object?


Object.get()

Object.keys()

Object.loop()

Object.each()


Q77. What will be logged to the console?


var a = ['dog', 'cat', 'hen'];

a[100] = 'fox';

console.log(a.length);


100

3

4

101


Q78. What is one difference between collections created with Map and collections created with Object?


You can iterate over values in a Map in their insertion order.

Keys in Maps can be strings.

You can access values in a Map without iterating over the whole collection.

You can count the records in a Map with a single method call.


Q79. What is the value of dessert.type after executing this code?


const dessert = { type: 'pie' };

dessert.type = 'pudding';


Pudding

pie

The code will throw an error.

undefined


Q80. Which of the following operators can be used to do a short-circuit evaluation?


++

--

==

||


Q81. Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?


Student.prototype = Person;

Student.prototype = Person();

Student.parent = Person;

Student.prototype = new Person();


Q82. Why would you include a "use strict" statement in a JavaScript file?


to tell parsers to interpret your JavaScript syntax loosely

to tell parsers to enforce all JavaScript syntax rules when processing your code

to instruct the browser to automatically fix any errors it finds in the code

to enable ES6 features in your code


Q83. Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?


const

var

Let

all of them


Q84. Which of the following values is not a Boolean false?


Boolean(0)

Boolean("")

Boolean(NaN)

Boolean("false")


Q85. What is the result in the console of running the code shown?


var Storm = function () {};

Storm.prototype.precip = 'rain';

var WinterStorm = function () {};

WinterStorm.prototype = new Storm();

WinterStorm.prototype.precip = 'snow';

var bob = new WinterStorm();

console.log(bob.precip);

 

'rain'

'snow'

Storm()

undefined


Q86. You need to match a time value such as 12:00:32. Which of the following regular expressions would work for your code?


/[0-9]{2,}:[0-9]{2,}:[0-9]{2,}/

/\d\d:\d\d:\d\d/

/[0-9]+:[0-9]+:[0-9]+/

/ : : /


Q87. What is the result in the console of running this code?


'use strict';

function logThis() {

  this.desc = 'logger';

  console.log(this);

}

new logThis();


undefined

{desc: "logger"}

window

function


Q88. How would you reference the text 'avenue' in the code shown?

let roadTypes = ['street', 'road', 'avenue', 'circle'];


roadTypes[2]

roadTypes.2

roadTypes[3]

roadTypes.3



Q89. What is the result of running this statement?

console.log(typeof 42);


'float'

'value'

'number'

'integer'


Q90. Which property references the DOM object that dispatched an event?


target

self

object

source


Q91. You're adding error handling to the code shown. Which code would you include within the 

if statement to specify an error message?


function addNumbers(x, y) {

  if (isNaN(x) || isNaN(y)) {

  }

}


exception('One or both parameters are not numbers')

throw('One or both parameters are not numbers')

catch('One or both parameters are not numbers')

error('One or both parameters are not numbers')


Q92. Which method converts JSON data to a JavaScript object?

 

JSON.fromString();

JSON.toObject()

JSON.stringify()

JSON.parse()


Q93. When would you use a conditional statement?


When you want your code to choose between multiple options.

When you want to group data together.

When you want to loop through a group of statement.

When you want to reuse a set of statements multiple times.



You may be interested to qualify for other skill tests Click the below links

FiverrExam

GoogleSkillShop

GoogleSkills

MedicalQuiz

MicroSoftTests

TestQuiz

Post a Comment (0)
Previous Post Next Post