Download as pdf or txt
Download as pdf or txt
You are on page 1of 96

31/08/2023, 22:04 30 seconds of interviews

11 12 1
10 2
9 3
8 4
7 6 5

alt

alt

alt

alt

https://30secondsofinterviews.org 1/96
31/08/2023, 22:04 30 seconds of interviews

alt

. alt

/* block component */
.block {
}

/* element */
.block__element {
}

/* modifier */
.block__element--modifier {
}

<nav class="navbar">
<a href="/" class="navbar__link navbar__link--active"></a>
<a href="/" class="navbar__link"></a>

https://30secondsofinterviews.org 2/96
31/08/2023, 22:04 30 seconds of interviews

<a href="/" class="navbar__link"></a>


</nav>

navbar navbar__link
navbar navbar__link--active

navbar__link

is-*

<a href="/" class="navbar__link is-active"></a>

.navbar__link.is-active {
}

https://30secondsofinterviews.org 3/96
31/08/2023, 22:04 30 seconds of interviews

src="js/script.js" src="js/script.js?v=2"

lighten darken transparentize

https://30secondsofinterviews.org 4/96
31/08/2023, 22:04 30 seconds of interviews

==
===

===
==

==

https://30secondsofinterviews.org 5/96
31/08/2023, 22:04 30 seconds of interviews

const Component = () => "Hello"


const componentElement = <Component />
const domNodeElement = <div />

col-{n} / 12

<div class="row">
<div class="col-2"></div>
<div class="col-7"></div>
<div class="col-3"></div>
</div>

.row display: flex; flex

flex-grow

https://30secondsofinterviews.org 6/96
31/08/2023, 22:04 30 seconds of interviews

.row {
display: flex;
}

.col-2 {
flex: 2;
}

.col-7 {
flex: 7;
}

.col-3 {
flex: 3;
}

<header>
<footer>

<header> <footer>
<body>
<article> <section>

https://30secondsofinterviews.org 7/96
31/08/2023, 22:04 30 seconds of interviews

<header> <article> <section>


<footer>

<header>

<article>

<section>

<footer>

<form> <table>

https://30secondsofinterviews.org 8/96
31/08/2023, 22:04 30 seconds of interviews

@media

all
print

screen
speech

i++
++i

let i = 0
i++ // 0
// i === 1

https://30secondsofinterviews.org 9/96
31/08/2023, 22:04 30 seconds of interviews

let i = 0
++i // 1
// i === 1

Promise

{} /* */

const tree = (
<div>
{/* Comment */}
<p>Text</p>
https://30secondsofinterviews.org 10/96
31/08/2023, 22:04 30 seconds of interviews

</div>
)

// Stateful class component


class App extends Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
render() {
// ...
}
}

// Stateful function component


function App() {
const [count, setCount] = useState(0)
return // ...
}

https://30secondsofinterviews.org 11/96
31/08/2023, 22:04 30 seconds of interviews

useState()

this

defer async <script>

https://30secondsofinterviews.org 12/96
31/08/2023, 22:04 30 seconds of interviews

defer

DOMContentLoaded defer

async

async

src

<script src="myscript.js"></script>
<script src="myscript.js" defer></script>
<script src="myscript.js" async></script>

defer <head>

defer
async

defer
DOMContentLoaded

batches

/**
It accepts two objects as arguments: the first object is the recipe
for the food, while the second object is the available ingredients.
Each ingredient's value is a number representing how many units the

https://30secondsofinterviews.org 13/96
31/08/2023, 22:04 30 seconds of interviews

`batches(recipe, available)`
*/

// 0 batches can be made


batches(
{ milk: 100, butter: 50, flour: 5 },
{ milk: 132, butter: 48, flour: 51 }
)
batches(
{ milk: 100, flour: 4, sugar: 10, butter: 5 },
{ milk: 1288, flour: 9, sugar: 95 }
)

// 1 batch can be made


batches(
{ milk: 100, butter: 50, cheese: 10 },
{ milk: 198, butter: 52, cheese: 10 }
)

// 2 batches can be made


batches(
{ milk: 2, sugar: 40, butter: 20 },
{ milk: 5, sugar: 120, butter: 500 }
)

Object.keys()
Array.prototype.map()

https://30secondsofinterviews.org 14/96
31/08/2023, 22:04 30 seconds of interviews

NaN
0

...
Math.min()

Math.floor()

const batches = (recipe, available) =>


Math.floor(
Math.min(...Object.keys(recipe).map(k => available[k] / recipe[
)

bind
Function.prototype.bind

function example() {
console.log(this)
}
const boundExample = bind(example, { a: true })
boundExample.call({ b: true }) // logs { a: true }

...
fn Function.prototype.apply

const bind = (fn, context) => (...args) => fn.apply(context, args)

https://30secondsofinterviews.org 15/96
31/08/2023, 22:04 30 seconds of interviews

setState

setState
setState

setState({ name: "sudheer" }, () => {


console.log("The name has updated and component re-rendered")
})

setState

https://30secondsofinterviews.org 16/96
31/08/2023, 22:04 30 seconds of interviews

function onClick() {
console.log("The user clicked on the page.")
}
document.addEventListener("click", onClick)

map

const map = (arr, callback) => {


const result = []
for (let i = 0; i < arr.length; i++) {
result.push(callback(arr[i], i))
}
return result
}
map([1, 2, 3, 4, 5], n => n * 2) // [2, 4, 6, 8, 10]

className class

class className

const element = document.createElement("div")

https://30secondsofinterviews.org 17/96
31/08/2023, 22:04 30 seconds of interviews

element.className = "hello"

const element = {
attributes: {
class: "hello"
}
}

const { class } = this.props // Error


const { className } = this.props // All good
const { class: className } = this.props // All good, but cumbersome

class
class
className

className class

...

https://30secondsofinterviews.org 18/96
31/08/2023, 22:04 30 seconds of interviews

const obj = { a: 1, b: 2 }
const shallowClone = { ...obj }

JSON.parse(JSON.stringify(obj))

Object.assign({}, obj)
Object.keys(obj).reduce((acc, key) => (acc[key] = obj[key],
acc), {})

== ===

https://30secondsofinterviews.org 19/96
31/08/2023, 22:04 30 seconds of interviews

true

function isDeepEqual(obj1, obj2, testPrototypes = false) {


if (obj1 === obj2) {
return true
}

if (typeof obj1 === "function" && typeof obj2 === "function") {


return obj1.toString() === obj2.toString()
}

if (obj1 instanceof Date && obj2 instanceof Date) {


return obj1.getTime() === obj2.getTime()
}

if (
Object.prototype.toString.call(obj1) !==
Object.prototype.toString.call(obj2) ||
typeof obj1 !== "object"
) {
return false
}

const prototypesAreEqual = testPrototypes


? isDeepEqual(
Object.getPrototypeOf(obj1),
Object.getPrototypeOf(obj2),

https://30secondsofinterviews.org 20/96
31/08/2023, 22:04 30 seconds of interviews

true
)
: true

const obj1Props = Object.getOwnPropertyNames(obj1)


const obj2Props = Object.getOwnPropertyNames(obj2)

return (
obj1Props.length === obj2Props.length &&
prototypesAreEqual &&
obj1Props.every(prop => isDeepEqual(obj1[prop], obj2[prop]))
)
}

http://mydomain.com
http://yourdomain.com

XMLHttpRequest fetch

https://30secondsofinterviews.org 21/96
31/08/2023, 22:04 30 seconds of interviews

Content
content-box width

content-box height

Padding

padding-box width padding-box height

Border
border-box width border-box height

margin-box width margin-box height

https://30secondsofinterviews.org 22/96
31/08/2023, 22:04 30 seconds of interviews

https://30secondsofinterviews.org 23/96
31/08/2023, 22:04 30 seconds of interviews

<head> defer DOMContentLoaded

document.getElementById() document.querySelector()

innerHTML

em rem

em rem font-size

em font-size
rem font-size
html

font-size 16px

em rem

https://30secondsofinterviews.org 24/96
31/08/2023, 22:04 30 seconds of interviews

Event.target

document.querySelectorAll("button").forEach(button => {
button.addEventListener("click", handleButtonClick)
})

document.addEventListener("click", e => {
if (e.target.closest("button")) {

https://30secondsofinterviews.org 25/96
31/08/2023, 22:04 30 seconds of interviews

handleButtonClick()
}
})

let x = 0

function declaration() {}

if (true) {
}

https://30secondsofinterviews.org 26/96
31/08/2023, 22:04 30 seconds of interviews

// Assign `x` to the absolute value of `y`.


var x
if (y >= 0) {
x = y
} else {
x = -y
}

y >= 0
true false

5 + 5 // => 10

lastCharacter("input") // => "t"

true === true // => true

// Assign `x` as the absolute value of `y`.


var x = y >= 0 ? y : -y

https://30secondsofinterviews.org 27/96
31/08/2023, 22:04 30 seconds of interviews

true false

false
undefined

null
""
NaN

0 +0 -0

Boolean

Boolean("") // false
Boolean([]) // true

! !

https://30secondsofinterviews.org 28/96
31/08/2023, 22:04 30 seconds of interviews

!!"" // false
!![] // true

n Array.prototype.reduce()

const fibonacci = n =>


[...Array(n)].reduce(
(acc, val, i) => acc.concat(i > 1 ? acc[i - 1] + acc[i - 2] : i
[]
)

0.1 + 0.2 === 0.3

false

0.1 + 0.2 // 0.30000000000000004

https://30secondsofinterviews.org 29/96
31/08/2023, 22:04 30 seconds of interviews

const approxEqual = (n1, n2, epsilon = 0.0001) => Math.abs(n1 - n2)


approxEqual(0.1 + 0.2, 0.3) // true

map()
forEach()

map()

forEach()

forEach()
map()

forEach()

map()

https://30secondsofinterviews.org 30/96
31/08/2023, 22:04 30 seconds of interviews

var foo = 1
var foobar = function() {
console.log(foo)
var foo = 2
}
foobar()

foo console.log
foo

console.log()

undefined 2

strict

https://30secondsofinterviews.org 31/96
31/08/2023, 22:04 30 seconds of interviews

console.log(hoist)
var hoist = "value"

var hoist
console.log(hoist)
hoist = "value"

hoist undefined "value"

myFunction() // No error; logs "hello"


function myFunction() {
console.log("hello")
}

myFunction() // Error: `myFunction` is not a function


var myFunction = function() {
console.log("hello")
}

https://30secondsofinterviews.org 32/96
31/08/2023, 22:04 30 seconds of interviews

HTML5

HTML5

HTML5 HTML5

https://30secondsofinterviews.org 33/96
31/08/2023, 22:04 30 seconds of interviews

<button onclick="handleClick()"></button>

<button onClick={handleClick} />

false

preventDefault

<a href="#" onclick="console.log('The link was clicked.'); return fa

function handleClick(e) {
e.preventDefault()
console.log("The link was clicked.")
}

https://30secondsofinterviews.org 34/96
31/08/2023, 22:04 30 seconds of interviews

<DOCTYPE>

checked="checked" checked

const myLibrary = (function() {


var privateVariable = 2
return {
publicMethod: () => privateVariable

https://30secondsofinterviews.org 35/96
31/08/2023, 22:04 30 seconds of interviews

}
})()
privateVariable // ReferenceError
myLibrary.publicMethod() // 2

function App({ messages, isVisible }) {


return (
<div>
if (messages.length > 0) {
<h2>You have {messages.length} unread messages.</h2>
} else {
<h2>You have no unread messages.</h2>
}
if (isVisible) {
<p>I am visible.</p>
}
</div>
)
}

https://30secondsofinterviews.org 36/96
31/08/2023, 22:04 30 seconds of interviews

&& ? : if else

function App({ messages, isVisible }) {


return (
<div>
{messages.length > 0 ? (
<h2>You have {messages.length} unread messages.</h2>
) : (
<h2>You have no unread messages.</h2>
)}
{isVisible && <p>I am visible.</p>}
</div>
)
}

const todoItems = todos.map(todo => <li key={todo.id}>{todo.text}</

<li>

https://30secondsofinterviews.org 37/96
31/08/2023, 22:04 30 seconds of interviews

<li>

https://30secondsofinterviews.org 38/96
31/08/2023, 22:04 30 seconds of interviews

getDerivedStateFromProps

componentDidMount

shouldComponentUpdate

getSnapshotBeforeUpdate

componentDidUpdate
componentDidUpdate

componentDidUpdate

componentWillUnmount

componentDidCatch

https://30secondsofinterviews.org 39/96
31/08/2023, 22:04 30 seconds of interviews

getDerivedStateFromProps componentDidMount

getDerivedStateFromProps shouldComponentUpdate
getSnapshotBeforeUpdate componentDidUpdate

componentWillUnmount

componentDidCatch

https://30secondsofinterviews.org 40/96
31/08/2023, 22:04 30 seconds of interviews

mask("123456789") // "#####6789"

String.prototype.slice()

-4
String.prototype.padStart()

const mask = (str, maskChar = "#") =>


str.slice(-4).padStart(str.length, maskChar)

https://30secondsofinterviews.org 41/96
31/08/2023, 22:04 30 seconds of interviews

MIME Multi-purpose Internet Mail Extensions

MIME type

MIME type
application/msword

fs.readFile(filePath, function(err, data) {


if (err) {
// handle the error, the return is important here
// so execution stops here
return console.log(err)
}
// use the data object

https://30secondsofinterviews.org 42/96
31/08/2023, 22:04 30 seconds of interviews

console.log(data)
})

var isTrue = function(value, callback) {


if (value === true) {
callback(null, "Value was true.")
} else {
callback(new Error("Value is not true!"))
}
}

var callback = function(error, retval) {


if (error) {
console.log(error)
return
}
console.log(retval)
}

isTrue(false, callback)
isTrue(true, callback)
https://30secondsofinterviews.org 43/96
31/08/2023, 22:04 30 seconds of interviews

/*
{ stack: [Getter/Setter],
arguments: undefined,
type: undefined,
message: 'Value is not true!' }
Value was true.
*/

null undefined

undefined

null null
undefined
undefined null

undefined
null

typeof undefined "undefined"


typeof null "object"

undefined == null true

https://30secondsofinterviews.org 44/96
31/08/2023, 22:04 30 seconds of interviews

const person = {
name: "John",
age: 50,
birthday() {
this.age++
}
}
person.birthday() // person.age === 51

new

https://30secondsofinterviews.org 45/96
31/08/2023, 22:04 30 seconds of interviews

function Person(name, age) {


this.name = name
this.age = age
}
Person.prototype.birthday = function() {
this.age++
}
const person1 = new Person("John", 50)
const person2 = new Person("Sally", 20)
person1.birthday() // person1.age === 51
person2.birthday() // person2.age === 21

new

this

const createPerson = (name, age) => {


const birthday = () => person.age++
const person = { name, age, birthday }
return person
}
const person = createPerson("John", 50)
person.birthday() // person.age === 51

Object.create()

const personProto = {
birthday() {
this.age++
}
https://30secondsofinterviews.org 46/96
31/08/2023, 22:04 30 seconds of interviews

}
const person = Object.create(personProto)
person.age = 50
person.birthday() // person.age === 51

Object.create()

Object.create(personProto, {
age: {
value: 50,
writable: true,
enumerable: true
}
})

https://30secondsofinterviews.org 47/96
31/08/2023, 22:04 30 seconds of interviews

function myFunction(parameter1, parameter2) {


console.log(arguments[0]) // "argument1"
}
myFunction("argument1", "argument2")

arguments

myFunction.length

bind

https://30secondsofinterviews.org 48/96
31/08/2023, 22:04 30 seconds of interviews

<button onClick={() => this.handleClick(id)} />


<button onClick={this.handleClick.bind(this, id)} />

Promise

Promise

new Promise((resolve, reject) => {


setTimeout(() => {
resolve("result")
}, 100)
})
.then(console.log)
.catch(console.error)

Promise

https://30secondsofinterviews.org 49/96
31/08/2023, 22:04 30 seconds of interviews

new

Object.create()

const a = [1, 2, 3]
const b = [1, 2, 3]
const c = "1,2,3"

console.log(a == c)
console.log(a == b)

console.log true

console.log false

https://30secondsofinterviews.org 50/96
31/08/2023, 22:04 30 seconds of interviews

rel="noopener"

rel="noopener" <a>

window.opener

rel="noopener"
rel="noopener"

posts

users comments

https://30secondsofinterviews.org 51/96
31/08/2023, 22:04 30 seconds of interviews

posts

/posts/

/posts/new
/posts/:id

/posts/:id

function greet() {
return
{
message: "hello"
}
}

return

undefined

https://30secondsofinterviews.org 52/96
31/08/2023, 22:04 30 seconds of interviews

const previousLine = 3
;[1, 2, previousLine].map(n => n * 2)

const previousLine = 3
;(function() {
// ...
})()

3
3

https://30secondsofinterviews.org 53/96
31/08/2023, 22:04 30 seconds of interviews

true || false

false true

false && true

true || nonexistentFunction()
false && nonexistentFunction()

true || nonexistentFunction() || window.nothing.wouldThrowError


true || window.nothing.wouldThrowError
true

https://30secondsofinterviews.org 54/96
31/08/2023, 22:04 30 seconds of interviews

const options = {}
const setting = options.setting || "default"
setting // "default"

// Instead of:
addEventListener("click", e => {
if (e.target.closest("button")) {
handleButtonClick(e)
}
})

// You can take advantage of short-circuit evaluation:


addEventListener(
"click",
e => e.target.closest("button") && handleButtonClick(e)
)

e.target
"button"

https://30secondsofinterviews.org 55/96
31/08/2023, 22:04 30 seconds of interviews

background-image background-position background-size


background

background-image background-position background-size

https://30secondsofinterviews.org 56/96
31/08/2023, 22:04 30 seconds of interviews

XMLHttpRequest setTimeout

alert

typeof typeof 0

"string"

https://30secondsofinterviews.org 57/96
31/08/2023, 22:04 30 seconds of interviews

typeof 0 "number" typeof


"number" "string"

Boolean Null Undefined Number String Symbol


Object

Symbol
Array Date function object

var let const

window

https://30secondsofinterviews.org 58/96
31/08/2023, 22:04 30 seconds of interviews

var

setTimeout
i 10

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


setTimeout(() => {
// logs `10` ten times
console.log(i)
})
}

/* Solutions with `var` */


for (var i = 0; i < 10; i++) {
// Passed as an argument will use the value as-is in
// that point in time
setTimeout(console.log, 0, i)
}

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


// Create a new function scope that will use the value
// as-is in that point in time
;(i => {
setTimeout(() => {
console.log(i)
})

https://30secondsofinterviews.org 59/96
31/08/2023, 22:04 30 seconds of interviews

})(i)
}

let

for (let i = 0; i < 10; i++) {


setTimeout(() => {
// logs 0, 1, 2, 3, ...
console.log(i)
})
}

const

const myObject = {}
myObject.prop = "hello!" // No error
myObject = "hello" // Error

let const

https://30secondsofinterviews.org 60/96
31/08/2023, 22:04 30 seconds of interviews

var let
var

var const

let

<script>

https://30secondsofinterviews.org 61/96
31/08/2023, 22:04 30 seconds of interviews

textContent innerHTML

1ms

arr[arr.length - 1]

1ms

https://30secondsofinterviews.org 62/96
31/08/2023, 22:04 30 seconds of interviews

arr.filter(fn)

1000ms

arr.some(fn)

1ms <= x <= 1000ms

arr.sort(fn)

10000ms

sort()

for (let i = 0; i < arr.length; i++) {


for (let j = 0; j < arr.length; j++) {
// ...
}
}

https://30secondsofinterviews.org 63/96
31/08/2023, 22:04 30 seconds of interviews

1000000ms

const permutations = arr => {


if (arr.length <= 2) return arr.length === 2 ? [arr, [arr[1], arr
return arr.reduce(
(acc, item, i) =>
acc.concat(
permutations([...arr.slice(0, i), ...arr.slice(i + 1)]).map
item,
...val
])
),
[]
)
}

Infinity

getData(function(a) {
getMoreData(a, function(b) {
getMoreData(b, function(c) {
getMoreData(c, function(d) {
getMoreData(d, function(e) {
https://30secondsofinterviews.org 64/96
31/08/2023, 22:04 30 seconds of interviews

// ...
})
})
})
})
})

async/await

await

async function asyncAwaitVersion() {


const a = await getData()
const b = await getMoreData(a)
const c = await getMoreData(b)
const d = await getMoreData(c)
const e = await getMoreData(d)
// ...
}

https://30secondsofinterviews.org 65/96
31/08/2023, 22:04 30 seconds of interviews

findDOMNode()

findDOMNode()

// Legacy approach using findDOMNode()


class MyComponent extends Component {
componentDidMount() {
findDOMNode(this).scrollIntoView()
}

render() {
return <div />
}
}

// Recommended approach using callback refs


class MyComponent extends Component {
componentDidMount() {
this.node.scrollIntoView()
}

render() {
return <div ref={node => (this.node = node)} />
}
}

https://30secondsofinterviews.org 66/96
31/08/2023, 22:04 30 seconds of interviews

findDOMNode()

children

children

React.Children.map

React.Children.forEach React.Children.count
React.Children.only React.Children.toArray

function GenericBox({ children }) {


return <div className="container">{children}</div>
}

function App() {
return (
<GenericBox>
<span>Hello</span> <span>World</span>
</GenericBox>
)
}

https://30secondsofinterviews.org 67/96
31/08/2023, 22:04 30 seconds of interviews

https://30secondsofinterviews.org 68/96
31/08/2023, 22:04 30 seconds of interviews

const { Provider, Consumer } = React.createContext(defaultValue)

<p> <div>

div ~ p {
background-color: blue;

https://30secondsofinterviews.org 69/96
31/08/2023, 22:04 30 seconds of interviews

<p>
<div>

div + p {
background-color: red;
}

https://30secondsofinterviews.org 70/96
31/08/2023, 22:04 30 seconds of interviews

static getDerivedStateFromError()

componentDidCatch().

class ErrorBoundary extends React.Component {


constructor(props) {
super(props)
this.state = { hasError: false }
}

// Use componentDidCatch to log the error


componentDidCatch(error, info) {
// You can also log the error to an error reporting service
logErrorToMyService(error, info)
}

// use getDerivedStateFromError to update state


static getDerivedStateFromError(error) {
// Display fallback UI
return { hasError: true };
}

https://30secondsofinterviews.org 71/96
31/08/2023, 22:04 30 seconds of interviews

render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>
}
return this.props.children
}
}

click mouseenter

document.addEventListener("click", function(event) {
// This callback function is run when the user
// clicks on the document.
})

https://30secondsofinterviews.org 72/96
31/08/2023, 22:04 30 seconds of interviews

const hub = createEventHub()


hub.on("message", function(data) {
console.log(`${data.username} said ${data.text}`)
})
hub.emit("message", {
username: "John",
text: "Hello?"
})

on emit

outline: 0;

https://30secondsofinterviews.org 73/96
31/08/2023, 22:04 30 seconds of interviews

box-shadow

:focus-visible

render() {
return (
<React.Fragment>
<ChildA />
<ChildB />
<ChildC />
</React.Fragment>
);
}

// Short syntax supported by Babel 7


render() {
return (
<>

https://30secondsofinterviews.org 74/96
31/08/2023, 22:04 30 seconds of interviews

<ChildA />
<ChildB />
<ChildC />
</>
);
}

.map
.reduce

https://30secondsofinterviews.org 75/96
31/08/2023, 22:04 30 seconds of interviews

const EnhancedComponent = higherOrderComponent(WrappedComponent)

localStorage
sessionStorage

localStorage sessionStorage

https://30secondsofinterviews.org 76/96
31/08/2023, 22:04 30 seconds of interviews

localStorage

sessionStorage

sessionStorage

localStorage sessionStorage

sessionStorage

sessionStorage

localStorage
sessionStorage

https://30secondsofinterviews.org 77/96
31/08/2023, 22:04 30 seconds of interviews

const numbers = [1, 2, 3, 4, 5]


const numbersDoubled = []
for (let i = 0; i < numbers.length; i++) {
numbersDoubled[i] = numbers[i] * 2
}

const numbers = [1, 2, 3, 4, 5]


const numbersDoubled = numbers.map(n => n * 2)

https://30secondsofinterviews.org 78/96
31/08/2023, 22:04 30 seconds of interviews

const memoize = fn => {


const cache = new Map()
return value => {
const cachedResult = cache.get(value)
if (cachedResult !== undefined) return cachedResult
const result = fn(value)
cache.set(value, result)
return result
}
}

https://30secondsofinterviews.org 79/96
31/08/2023, 22:04 30 seconds of interviews

this

this

Function.prototype.bind()
this

constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
// Perform some logic
}

bind
constructor

handleClick = () => {
console.log('this is:', this);
}

render() {
return (
<button onClick={this.handleClick}>
Click me
</button>
);
}

https://30secondsofinterviews.org 80/96
31/08/2023, 22:04 30 seconds of interviews

this

<button onClick={e => this.handleClick(e)}>Click me</button>

shouldComponentUpdate PureComponent

bind

https://30secondsofinterviews.org 81/96
31/08/2023, 22:04 30 seconds of interviews

String.prototype

Array.prototype

const myString = "hello!"


myString.replace("!", "") // returns a new string, cannot mutate the

const originalArray = [1, 2, 3]


originalArray.push(4) // mutates originalArray, now [1, 2, 3, 4]
originalArray.concat(4) // returns a new array, does not mutate the

NaN
NaN

NaN

isNaN() Number.isNaN()
const isNaN = x => x !== x

https://30secondsofinterviews.org 82/96
31/08/2023, 22:04 30 seconds of interviews

pipe

const square = v => v * v


const double = v => v * 2
const addOne = v => v + 1
const res = pipe(square, double, addOne)
res(3) // 19; addOne(double(square(3)))

...
Array.prototype.reduce()

const pipe = (...fns) => x => fns.reduce((v, fn) => fn(v), x)

https://30secondsofinterviews.org 83/96
31/08/2023, 22:04 30 seconds of interviews

ReactDOM.createPortal(child, container)

child

container

isRequired

https://30secondsofinterviews.org 84/96
31/08/2023, 22:04 30 seconds of interviews

propTypes

import PropTypes from "prop-types"

class User extends React.Component {


static propTypes = {
name: PropTypes.string.isRequired,
age: PropTypes.number.isRequired
}

render() {
return (
<h1>Welcome, {this.props.name}</h1>
<h2>Age, {this.props.age}
)
}
}

propTypes
propTypes

https://30secondsofinterviews.org 85/96
31/08/2023, 22:04 30 seconds of interviews

const a = (x, y) => x + y


const b = (arr, value) => arr.concat(value)
const c = arr => [...arr].sort((a, b) => a - b)

const a = (x, y) => x + y + Math.random()


const b = (arr, value) => (arr.push(value), arr)
const c = arr => arr.sort((a, b) => a - b)

setInnerHTML

https://30secondsofinterviews.org 86/96
31/08/2023, 22:04 30 seconds of interviews

const nest = (items, id = null, link = "parent_id") =>


items
.filter(item => item[link] === id)
.map(item => ({ ...item, children: nest(items, item.id) }))

const comments = [
{ id: 1, parent_id: null, text: "First reply to post." },
{ id: 2, parent_id: 1, text: "First reply to comment #1." },
{ id: 3, parent_id: 1, text: "Second reply to comment #1." },
{ id: 4, parent_id: 3, text: "First reply to comment #3." },
{ id: 5, parent_id: 4, text: "First reply to comment #4." },
{ id: 6, parent_id: null, text: "Second reply to post." }
]

nest(comments)
/*
[
{ id: 1, parent_id: null, text: "First reply to post.", children:
{ id: 6, parent_id: null, text: "Second reply to post.", children
]
*/

filter()

map()

https://30secondsofinterviews.org 87/96
31/08/2023, 22:04 30 seconds of interviews

React.createRef()
ref
ref

class MyComponent extends React.Component {


constructor(props) {
super(props)
this.myRef = React.createRef()
}

render() {
return <div ref={this.myRef} />
}
}

https://30secondsofinterviews.org 88/96
31/08/2023, 22:04 30 seconds of interviews

React.createRef()
ref

Array.isArray // static method of Array


Array.prototype.push // instance method of Array

Array.isArray

const arr = [1, 2, 3]


arr.push(4)
Array.push(arr, 4)

https://30secondsofinterviews.org 89/96
31/08/2023, 22:04 30 seconds of interviews

this

this

this
call() apply() bind()
this

call()

this

this

this

var myObject = {
property: this,
regularFunction: function() {
return this
},
arrowFunction: () => {
return this
},
iife: (function() {
return this
})()
}
myObject.regularFunction() // myObject
myObject["regularFunction"]() // my Object

myObject.property // NOT myObject; lexical `this`


myObject.arrowFunction() // NOT myObject; lexical `this`

https://30secondsofinterviews.org 90/96
31/08/2023, 22:04 30 seconds of interviews

myObject.iife // NOT myObject; lexical `this`


const regularFunction = myObject.regularFunction
regularFunction() // NOT myObject; lexical `this`

this

document.body.addEventListener("click", function() {
console.log(this) // document.body
})

this

class Example {
constructor() {
console.log(this) // myExample
}
}
const myExample = new Example()

call() apply() this

var myFunction = function() {


return this
}
myFunction.call({ customThis: true }) // { customThis: true }

this

this

https://30secondsofinterviews.org 91/96
31/08/2023, 22:04 30 seconds of interviews

var obj = {
arr: [1, 2, 3],
doubleArr() {
return this.arr.map(function(value) {
// this is now this.arr
return this.double(value)
})
},
double() {
return value * 2
}
}
obj.doubleArr() // Uncaught TypeError: this.double is not a functio

this window

this undefined
Function.prototype.call Function.prototype.apply

this call
apply

Function.prototype.bind
this

this

function
this

https://30secondsofinterviews.org 92/96
31/08/2023, 22:04 30 seconds of interviews

data

https://30secondsofinterviews.org 93/96
31/08/2023, 22:04 30 seconds of interviews

'use strict'

'use strict'

eval() arguments

this this
null undefined
delete

https://30secondsofinterviews.org 94/96
31/08/2023, 22:04 30 seconds of interviews

<div class="counter">
<h1>0</h1>
<button>-</button>
<button>+</button>
</div>

{
nodeName: "div",
attributes: { class: "counter" },
children: [
{
nodeName: "h1",
attributes: {},
children: [0]
},
{
nodeName: "button",
attributes: {},
children: ["-"]
},
{
nodeName: "button",
attributes: {},
children: ["+"]
}
]
}

https://30secondsofinterviews.org 95/96
31/08/2023, 22:04 30 seconds of interviews

https://30secondsofinterviews.org 96/96

You might also like