Variables
Javascript data types; undefined
, null
, boolean
, string
, symbol
, number
, object
When JavaScript variables are declared, they have an initial value of undefined
. If you do a mathematical operation on an undefined
variable your result will be NaN
which means Not a Number. If you concatenate a string with an undefined
variable, you will get a literal string of "undefined"
.
Decimal
Not all real numbers can accurately be represented in floating point. This can lead to rounding errors
Length
To find the length of a string: string.length
Bracket Notation
To get the first character of the string string[0]
Immutable
In JavaScript, String
values are immutable, which means that they cannot be altered once created. The only way to change string would be assign it with a new string.
1 | var myStr = "Bob"; |
Array
Arrays in JavaScript can contain multiple types of values.
The entries of arrays are mutable and can be changed freely.
1 | let array = ["John", 23]; |
To check if an array contains element:
1 | arr.includes(element); |
String
In ES6 new feature startsWith()
, endsWith()
, includes()
, indexOf()
1 | const str = "Saturday night plans" |
Interview
- Difference between
forEach
andmap
.*
map
will return an array, forEach
won’t.
Difference between
apply
andcall
**
Explain the concept of ES6 Promises to a 5-year-old
*
What are the advantages of using ES6 maps over objects? What about using ES6 sets over arrays?
Algorithm question: excludeItems
*
Given 2 identical DOM trees(but not equal) and one element of the first DOM tree, how would you find this element in the second DOM tree?
https://www.glassdoor.com/Interview/Given-two-identical-DOM-trees-not-the-same-one-and-a-node-from-one-of-them-find-the-node-in-the-other-one-QTN_970047.htmWrite an array flatten function recursively and iteratively. The array can have multiple types.
*******
- In JavaScript, write a function that takes an array as input that can contain both ints and more arrays (which can also contain an array or int) and return the flattened array.
1 | [1, [2, [ [3, 4], 5], 6]] => [1, 2, 3, 4, 5, 6] |
Write an emitter class
**
- Support subscribing to events
- Support emitting events
- Support unsubscribing existing subscriptions by releasing them
==
vs===
*
event delegation
*
Given a picture, how would you hide/show a child picture on hovering on this parent?
***
- How would you ensure clicking on this picture would go to a specific link?
- How would you ensure the child is positioned in the top right of the parent pictjure?
Difference between array and object
*
One-way & Two-way binding
Functions you can perform on strings
*
Difference between block and inline
**
Given a node from a DOM tree, find the node in the same position from an identical DOM tree.
Callendar challenge (2015)
Given a grid of characters output a decoded message. The message for the following would be IROCKA. (diagonally down right and diagonally up right if you can’t go further)
1 | I B C A L K A |
Javascript asyn concepts: event bubbling, debounce (its variant)
CSS position: relative, static. Difference inside out
(debounce) If you were building a search tool and wanted search results to pop up as you typed, but the server call was taxing. Write a function that gets called on every key down but calls the server when the user stops typing for 400ms.
- How many times would
addEventListener('scroll', handleScroll);
run as the user looks at their News Feed? And what would be user experience if thehandleScroll
function takes 100ms to execute. - How could you implement debouncing? Say you wanted the
handleScroll
function to be called only after 200ms has passed between scroll events.
- How many times would
Array reduce function
Design a class with some member functions that requries JS concepts such as closure and callbacks.
Time complexity to traverse the balanced binary tree.
Implement a simple store class with
set(Node, value)
,get(Node)
, andhas(Node)
methods, which store a given Nodes with corresponding values.**
You are given an array of N elements in the form “property1: value1; property2: value2;…;propertyX: valueX;” for some some N and any X. There is also another array of M elements of the form “property: value”. You are supposed to write an algorithm to remove every element in the N length array that has a “property: value” pair in the M length array.
What’s structure of DOM. What’s the depth of the balanced DOM tree with n nodes>
https://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=191090&highlight=fb%2B%C7%B0%B6%CB
function animateRight(element, duration, distance)
, smoothly move element in the duration.