<>
~
==!
!==
Reference Javascript Comparison Operators
Reference Differences between forEach and for loop
addTax = 50;
return addTax 50;
addTax(50);
addTax 50;
Reference functions in javascript
let rate = 100;
let 100 = rate;
100 = let rate;
rate = 100;
Reference Javascript Assignment operators
var student = new Person();
var student = construct Person;
var student = Person();
var student = construct Person();
Reference Javascript is synchronous and single threaded
a.prototype.belly[0]
Object.getPrototype0f (a).belly[0]
Animal.belly[0]
a.belly[0]
Reference Javascript Class static Keyword
A
B
C
D
E
A
B
C
D
Reference defining javascript functions
/[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 repetitions 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:
undefined
window
{desc: "logger"}
function
Reference accessing javascript arrays
'float'
'value'
'number'
'integer'
Reference javascript data types
self
object
target
source
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()
Reference convert json to javascript object
Reference javascript conditionals
Reference javascript for loops
Object.get()
Object.loop()
Object.each()
Object.keys()
Reference javascript object static methods
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.
Reference map methods javascript
Reference working with js objects
++
--
==
||
Reference short circuit javascript
Student.parent = Person;
Student.prototype = new Person();
Student.prototype = Person;
Student.prototype = Person();
Reference what is use strict in js
const
var
let
Reference var vs let vs const in js
Boolean(0)
Boolean("")
Boolean(NaN)
Boolean("false")
this
catch
function
array
Reference implicit js parameters for functions
x.get('Y')
x.Y
x.Y()
x.get().Y
Reference accessing before initialization
Reference efficiency of lookups
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.
Reference async attribute for html
import _ from 'lodash';
import 'lodash' as _;
import '_' from 'lodash;
import lodash as _ from 'lodash';
Reference how to import library in js
Reference arrays in js are objects
Reference what are generators in nodejs
Reference closures in js / nested functions
Reference functional programming
Explanation: You cannot invoke reduce on undefined object... It will throw (yourObject is not Defined...)
let arr = [];
typeof
delete
instanceof
void
Reference block vs function scope
throw
exception
catch
error
Reference throwing errors in js
Document.querySelector('class.pull')
document.querySelector('.pull');
Document.querySelector('pull')
Document.querySelector('#pull')
Reference javascript conditionals
1
then 1
1
then undefined
undefined
then undefined
undefined
then 1
forEach()
method differ from a for
statement?Reference Differences between forEach and for loop
({})
{}
{ return {};}
(({}))
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'
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
! This is a comment
# This is a comment
\\ This is a comment
// This is a comment
Reference comments in javascript
Reference javascript constructors
e.blockReload();
button.preventDefault();
button.blockReload();
e.preventDefault();
Reference events in javascript
function() { console.log('lorem ipsum'); }()();
function() { console.log('lorem ipsum'); }();
(function() { console.log('lorem ipsum'); })();
Reference what is an Immediately Invoked Function Expression
Document.querySelector('img')
Document.querySelectorAll('<img>')
Document.querySelectorAll('img')
Document.querySelector('<img>')
Reference what is the javascript window
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>; } }
ReferenceError: obj is not defined
{}
undefined
null
Reference working with objects
Reference functions in javascript
The output may change with each execution of code and cannot be determined.
.
Reference
https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#reasons_for_delays_longer_than_specified especially see the 'late timeouts' section.
Reference array deconstruction
Reference working with objects
map()
and the forEach()
methods on the Array prototype?forEach()
method returns a single output value, whereas the map()
method performs operation on each value in the array.forEach()
method iterates through an array with no return value.forEach()
methods returns a new array with a transformation applied on each item in the original array, whereas the map()
method iterates through an array with no return value.<script></script>
<js></js>
<javascript></javascript>
<code></code>
Reference Cross-Origin Resource Sharing
["Amazon","Borneo","Cerrado","Congo"]
["Cerrado", "Congo"]
["Congo"]
["Amazon","Borneo"]
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}
animals.filter(e => e === "jaguar");
animals.reverse();
animals.shift();
animals.pop();
Reference Javascript Array pop()
shift() - removes the FIRST element of an array and returns the removed item.
pop() - removes the LAST element of an array and returns the removed item.
reverse() - reverses the order of the elements in an array.
filter() - get every element in the array that meets the condition.
let vowels = "aeiou".toArray();
let vowels = Array.of("aeiou");
let vowels = {"a", "e", "i", "o", "u"};
let vowels = "aeiou";
Note: this question is same with Q46.
Reference ternary operator js
let matrix = [["You","Can"],["Do","It"],["!","!","!"]];
matrix[1[2]]
matrix[1][1]
matrix[1,2]
matrix[1][2]
bear.bind(roar);
roar.bind(bear);
roar.apply(bear);
bear[roar]();
a, b => { return c; }
a, b => c
{ a, b } => c
(a,b) => c
import printMe from './some-file';
import { printMe } from './some-file';
import default as printMe from './some-file';
const printMe = import './some-file';
Reference importing libraries in javascript
[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]
fetch()
?done()
then()
finally()
catch()
array.slice()
array.shift()
array.push()
array.replace()
string
array
Boolean
object
[4,5,6,7,8,9,10]
[4,5,6,7]
[1,2,3,4,5,6]
[4,5,6]
Reference functions in javascript
Reference MDN JavaScript Looping code
Explanation: The pop() method removes the last element from an array and returns that element. This method changes the length of the array.
[]
undefined
0
null
line 5, because lion cannot be reassigned a value
line 6, because the += operator cannot be used with the undefined variable bear
line 5, because the prefix (++) operator does not exist in JavaScript
line 3, because the variable bear is left undefined
result
after running this code?["Name", "Age", "HairColor"]
["DAVE", 40, "BLUE"]
["NAME", "AGE", "HAIRCOLOR"]
animals.every(key)
animals.some(key).length === 1
animals.filter(key) === true
animals.some(key)
Reference Array.prototype.some
undefined
None of these answers, as static is not a feature in Javascript.
60
80
a.b
on obj
without throwing an error if a is undefined?obj?.a.b
obj.a?.b
obj[a][b]
obj.?a.?b
Reference Optional chaining (?.)
ReferenceError
about x
.18
.undefined
.ReferenceError
about y
.[1,2,5,7]
[[1, 2], [5, 7]]
[2,7]
[2,1,7,5]
a['x'] === b['x']
a != b
a === b
a.x === b.x
Nothing. It resuults in a ReferenceError.
decimal
float
number
3
4
6
7
Nothing is printed to the console.
grunt
undefined
roar
cat.toJSON("type");
JSON.stringify(cat, ["type"]);
JSON.stringify(cat);
JSON.stringify(cat, /type/);
Reference: defer html script attribute
Reference: String.prototype.includes()
Reference: developer.mozilla Set