-
<>
-
~
-
==!
-
!==
- Only a for statement uses a callback function.
- A for statement is generic, but a forEach 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.
function addTax(total) {
return total * 1.05;
}
- addTax = 50;
- return addTax 50;
- addTax(50);
- addTax 50;
Q4. Which statement is the correct way to create a variable called rate and assign it the value 100?
- let rate = 100;
- let 100 = rate;
- 100 = let rate;
- rate = 100;
- var student = new Person();
- var student = construct Person;
- var student = Person();
- var student = construct Person();
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
let modal = document.querySelector('#results');
setTimeout(function () {
modal.classList.remove('hidden');
}, 10000);
- immediately
- after results are received from the HTTP request
- after 10 second
- after 10,000 seconds
Q8. 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);
}
- [x]
for (var i = 1; i <= 4; i++) {
(function (j) {
setTimeout(function () {
console.log(j);
}, j * 1000);
})(i);
}
- [ ]
for (var j = 1; j <= 4; j++) {
setTimeout(function () {
console.log(j);
}, j * 1000);
}
- It reloads the document whenever the value changes.
- It returns a reference to a variable in its parent scope.
- It completes execution without returning.
- It copies a local variable to the global scope.
- [x]
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;
};
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);
- Storm()
- undefined
- 'rain'
- 'snow'
Q12. 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]+/
- / : : /
NOTE: The first three are all partially correct and will match digits, but the second option is the most correct because it will only match 2 digit time values (12:00:32). The first option would have worked if the repitions range looked like [0-9]{2}
, however because of the comma [0-9]{2,}
it will select 2 or more digits (120:000:321). The third option will any range of time digits, single and multiple (meaning 1:2:3
will also match).
More resources:
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();
- undefined
- window
- {desc: "logger"}
- function
let roadTypes = ['street', 'road', 'avenue', 'circle'];
- roadTypes.2
- roadTypes[3]
- roadTypes.3
- roadTypes[2]
console.log(typeof 42);
- 'float'
- 'value'
- 'number'
- 'integer'
- self
- object
- target
- source
Q17. 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')
- catch('One or both parameters are not numbers')
- error('One or both parameters are not numbers')
- throw('One or both parameters are not numbers')
- JSON.fromString();
- JSON.parse()
- JSON.toObject()
- JSON.stringify()
- When you want to reuse a set of statements multiple times.
- 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.
for (var i = 0; i < 5; i++) {
console.log(i);
}
- 12345
- 1234
- 01234
- 012345
Q21. Which Object method returns an iterable that can be used to iterate over the properties of an object?
- Object.get()
- Object.loop()
- Object.each()
- Object.keys()
var a = ['dog', 'cat', 'hen'];
a[100] = 'fox';
console.log(a.length);
- 101
- 3
- 4
- 100
Q23. 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.
- You can count the records in a Map with a single method call.
- Keys in Maps can be strings.
- You can access values in a Map without iterating over the whole collection.
Explanation: Map.prototype.size returns the number of elements in a Map, whereas Object does not have a built-in method to return its size.
const dessert = { type: 'pie' };
dessert.type = 'pudding';
- pie
- The code will throw an error.
- pudding
- undefined
- ReferenceError
- True
- 0
- false
- ++
- --
- ==
- ||
Q27. Which statement sets the Person constructor as the parent of the Student constructor in the prototype chain?
- Student.parent = Person;
- Student.prototype = new Person();
- Student.prototype = Person;
- Student.prototype = Person();
- 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
Q29. Which Variable-defining keyword allows its variable to be accessed (as undefined) before the line that defines it?
- all of them
- const
- var
- let
- Boolean(0)
- Boolean("")
- Boolean(NaN)
- Boolean("false")
- this
- catch
- function
- array
- Arguments
- args
- argsArray
- argumentsList
class X {
get Y() {
return 42;
}
}
var x = new X();
- x.get('Y')
- x.Y
- x.Y()
- x.get().Y
sum(10, 20);
diff(10, 20);
function sum(x, y) {
return x + y;
}
let diff = function (x, y) {
return x - y;
};
- 30, ReferenceError, 30, -10
- 30, ReferenceError
- 30, -10
- ReferenceError, -10
Q35. 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.
Explanation: Records in an object can be retrieved using their key which can be any given value (e.g. an employee ID, a city name, etc), whereas to retrieve a record from an array we need to know its index.
- 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.
- It can be used only for external JavaScript code.
-
import _ from 'lodash';
-
import 'lodash' as _;
-
import '_' from 'lodash;
-
import lodash as _ from 'lodash';
[] == [];
- True
- undefined
- []
- False
- Generator function
- Arrow function
- Async/ Await function
- Promise function
var v = 1;
var f1 = function () {
console.log(v);
};
var f2 = function () {
var v = 2;
f1();
};
f2();
- 2
- 1
- Nothing - this code will throw an error.
- undefined
- 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.
Q42. 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's declared but has no value.
- 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.
Explanation: You cannot invoke reduce on undefined object... It will throw (yourObject is not Defined...)
let arr = [];
- 3
- 2
- 0
- 1
- typeof
- delete
- instanceof
- void
var start = 1;
if (start === 1) {
let end = 2;
}
- conditional
- block
- global
- function
const x = 6 % 2;
const y = x ? 'One' : 'Two';
- One
- undefined
- TRUE
- Two
- throw
- exception
- catch
- error
- The defer attribute can work synchronously.
- The defer attribute works only with generators.
- The defer attribute works only with promises.
- The defer attribute will asynchronously load the scripts in order.
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.
<p class="pull">lorem ipsum</p>
-
Document.querySelector('class.pull')
-
document.querySelector('.pull');
-
Document.querySelector('pull')
-
Document.querySelector('#pull')
let answer = true;
if (answer === false) {
return 0;
} else {
return 10;
}
- 10
- true
- false
- 0
var start = 1;
function setEnd() {
var end = 10;
}
setEnd();
console.log(end);
- 10
- 0
- ReferenceError
- undefined
function sayHello() {
console.log('hello');
}
console.log(sayHello.prototype);
- undefined
- "hello"
- an object with a constructor property
- an error message
- Object
- Set
- Array
- Map
function printA() {
console.log(answer);
var answer = 1;
}
printA();
printA();
-
1
then1
-
1
thenundefined
-
undefined
thenundefined
-
undefined
then1
- 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.
- forEach can be used only with an array, whereas for can be used with additional data types.
- for loops can be nested; whereas forEach loops cannot.
- => ({})
- => {}
- => { return {};}
- => (({}))
- 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
EXPLANATION: "to ensure that tasks further down in your code are not initiated until earlier tasks have completed" you use the normal (synchronous) flow where each command is executed sequentially. Asynchronous code allows you to break this sequence: start a long running function (AJAX call to an external service) and continue running the rest of the code in parallel.
-
[3] == [3]
-
3 == '3'
-
3 != '3'
-
3 === '3'
- 5thItem
- firstName
- grand total
- function
- cancel()
- stop()
- preventDefault()
- prevent()
- attachNode()
- getNode()
- querySelector()
- appendChild()
- break
- pass
- skip
- continue
- (a,b) => c
- a, b => {return c;}
- a, b => c
- { a, b } => c
Q65. 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
-
! This is a comment
-
# This is a comment
-
\\ This is a comment
-
// This is a comment
Q67. 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
- create()
- new()
- constructor()
- init()
let a = 5;
console.log(++a);
- 4
- 10
- 6
- 5
Q70. 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();
-
function() { console.log('lorem ipsum'); }()();
-
function() { console.log('lorem ipsum'); }();
-
(function() { console.log('lorem ipsum'); })();
-
Document.querySelector('img')
-
Document.querySelectorAll('<img>')
-
Document.querySelectorAll('img')
-
Document.querySelector('<img>')
- 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
- DELETE
- GET
- PATCH
- POST
Q75. Which event is fired on a text field within a form when a user tabs to it, or clicks or touches it?
- focus
- blur
- hover
- enter
function logThis() {
console.log(this);
}
logThis();
- function
- undefined
- Function.prototype
- window
const Greeting = ({ name }) => <h1>Hello {name}!</h1>;
-
class Greeting extends React.Component { render() { return <h1>Hello {this.props.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>; } }
useEffect(() => {
// do things
}, []);
- componentWillUnmount
- componentDidUpdate
- render
- componentDidMount
var obj;
console.log(obj);
- ReferenceError: obj is not defined
- {}
- undefined
- null
class TaxCalculator {
static calculate(total) {
return total * 0.05;
}
}
- calculate(50);
- new TaxCalculator().calculate($50);
- TaxCalculator.calculate(50);
- new TaxCalculator().calculate(50);
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.
console.log('I');
setTimeout(() => {
console.log('love');
}, 0);
console.log('Javascript!');
- [x]
I
Javascript!
love
- [ ]
love
I
Javascript!
-
The output may change with each execution of code and cannot be determined.
-
[ ]
I
love
Javascript!
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.
const foo = {
name: 'Albert',
};
- delete name from foo;
- delete foo.name;
- del foo.name;
- remove foo.name;
- There is no difference.
- The
forEach()
method returns a single output value, wheras themap()
method performs operation on each value in the array. - 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. - The
forEach()
methods returns a new array with a transformation applied on each item in the original array, wheras themap()
method iterates through an array with noreturn value.
function makeAdder(x) {
return function (y) {
return x + y;
};
}
var addFive = makeAdder(5);
console.log(addFive(3));
- overloading
- closure
- currying
- overriding
-
<script></script>
-
<js></js>
-
<javascript></javascript>
-
<code></code>
for (var i = 0; i < 5; i++) {
console.log(i);
}
- 0 1 2 3 4
- 0 1 2 3 4 5
- 1 2 3 4
- 1 2 3 4 5
const dessert = { type: 'pie' };
dessert.type = 'pudding';
const seconds = dessert;
seconds.type = 'fruit';
- pie
- fruit
- undefined
- pudding
Explanation: Assigning a variable (such as seconds) to an object (such as dessert) does not create a new object. The seconds variable merely becomes a reference for the dessert object. Any changes made to seconds will also reflect in dessert.
Q90. If your app receives data from a third-party API, which HTTP response header must the server specify to allow exceptions to the same-origin policy?
- Security-Mode
- Access-Control-Allow-Origin
- Different-Origin
- Same-Origin
Explanation: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
'use strict';
function logThis() {
this.desc = 'logger';
console.log(this);
}
new logThis();
- window
- undefined
- function
- {desc: "logger"}
- defer causes the script ta be loaded from the backup content delivery network (CDN).
- defer allows the browser ta continue processing the page while the script loads in the background.
- defer blacks the browser from processing HTML below the tag until the script is completely loaded.
- defer lazy loads the script, causing it to download only when it is called by another script on the page.
Explanation: If the defer attribute is set, it specifies that the script is downloaded in parallel to parsing the page, and executed after the page has finished parsing. HTML <script> defer Attribute
let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];
rainForests.splice(0, 2);
console.log(rainForests);
-
["Amazon","Borneo","Cerrado","Congo"]
-
["Cerrado", "Congo"]
-
["Congo"]
-
["Amazon","Borneo"]
Q94. Which missing line would allow you to create five variables(one,two,three,four,five) that correspond to their numerical values (1,2,3,4,5)?
const numbers = [1, 2, 3, 4, 5];
//MISSING LINE
-
const [one,two,three,four,five]=numbers
-
const {one,two,three,four,five}=numbers
-
const [one,two,three,four,five]=[numbers]
-
const {one,two,three,four,five}={numbers}
const obj = {
a: 1,
b: 2,
c: 3,
};
const obj2 = {
...obj,
a: 0,
};
console.log(obj2.a, obj2.b);
- Nothing, it will throw an error
- 0 2
- undefined 2
- undefined 2
let rainForests = ['Amazon', 'Borneo', 'Cerrado', 'Congo'];
rainForests.splice(0, 2);
console.log(rainForests);
-
["Amazon","Borneo","Cerrado","Congo"]
-
["Cerrado", "Congo"]
-
["Congo"]
-
["Amazon","Borneo"]
//Missing Line
for (var i = 0; i < vowels.length; i++) {
console.log(vowels[i]);
//Each letter printed on a separate line as follows;
//a
//e
//i
//o
//u
}
-
let vowels = "aeiou".toArray();
-
let vowels = Array.of("aeiou");
-
let vowels = {"a", "e", "i", "o", "u"};
-
let vowels = "aeiou";
const x = 6 % 2;
const y = x ? 'One' : 'Two';
console.log(y);
- undefined
- One
- true
- Two
let matrix = [["You","Can"],["Do","It"],["!","!","!"]];
-
matrix[1[2]]
-
matrix[1][1]
-
matrix[1,2]
-
matrix[1][2]
const animals = ['Rabbit', 'Dog', 'Cat'];
animals.unshift('Lizard');
- It adds "Lizard" to the start of the animals array.
- It adds "Lizard" to the end of the animals array.
- It replaces "Rabbit" with "Lizard" in the animals array.
- It replaces "Cat" with "Lizard" in the animals array.
let x = 6 + 3 + '3';
console.log(x);
- 93
- 12
- 66
- 633
Q102. Which statement can take a single expression as input and then look through a number of choices until one that matches that value is found?
- else
- when
- if
- switch
Q103. Which statement can take a single expression as input and then look through a number of choices until one that matches that value is found?
- else
- when
- if
- switch
Q104. Which choice is a valid example of an arrow function, assuming c is defined in the outer scope?
-
a, b => { return c; }
-
a, b => c
-
{ a, b } => c
-
(a,b) => c
-
create();
-
init();
-
constructor();
-
new();
//some-file.js
export const printMe = (str) => console.log(str);
-
import printMe from './some-file';
-
import { printMe } from './some-file';
-
import default as printMe from './some-file';
-
const printMe = import './some-file';
const arr1 = [2, 4, 6];
const arr2 = [3, 5, 7];
console.log([...arr1, ...arr2]);
-
[2, 3, 4, 5, 6, 7]
-
[3,5,7,2,4,6]
-
[3, 5, 7, 2, 4, 6]
-
[[2, 4, 6], [3, 5, 7]]
-
[2, 4, 6, 3, 5, 7]
-
done()
-
then()
-
finally()
-
catch()
-
array.slice()
-
array.shift()
-
array.push()
-
array.replace()
- do…while
- forEach
- while
- for
console.log(typeof 'blueberry');
- string
- array
- Boolean
- object
//HTML Markup
<div id="A">
<div id="B">
<div id="C">Click Here</div>
</div>
</div>
//JavaScript
document.querySelectorAll('div').forEach((e) => {
e.onclick = (e) => console.log(e.currentTarget.id);
});
- C B A
- A
- C
- A B C
javascript
var flagsJSON =
'{ "countries" : [' +
'{ "country":"Ireland" , "flag":"🇮🇪" },' +
'{ "country":"Serbia" , "flag":"🇷🇸" },' +
'{ "country":"Peru" , "flag":"🇵🇪" } ]}';
var flagDatabase = JSON.parse(flagsJSON);
- flagDatabase.countries[0].flag
- flagDatabase.countries[1].flag
- flagsJSON.countries[0].flag
- flagDatabase[1].flag
var sound = "grunt";
var bear = {
sound: "roar"
};
function roar() {
console.log(this.sound);
}
-
bear.bind(roar);
-
roar.bind(bear);
-
roar.apply(bear);
-
bear[roar]();
Reference Apply Reference this Reference bind
let animals = ["jaguar","eagle"];
//Missing Line
console.log(animals.pop()); //Prints jaguar
-
animals.filter(e => e === "jaguar");
-
animals.reverse();
-
animals.shift();
-
animals.pop();
Reference Javascript Array Reverse
class Animal {
static belly = [];
eat () {
Animal.belly.push("food");
}
}
let a = new Animal();
a.eat();
console.log(/* Snippet Here */); //Prints food
-
a.prototype.belly[0]
-
Object.getPrototype0f (a).belly[0]
-
Animal.belly[0]
-
a.belly[0]