JS FS BC W5

Chunhao Weng
5 min readJun 7, 2021

Random notes. Unorganized thoughts. Not an article.

Add an element at the end with push() and beginning with unshift().

Why unshift() though? A quick Google search…

https://www.quora.com/Why-are-so-many-languages-array-prepend-function-called-unshift-and-not-prepend

fascinating explanation

Yen-Ling asked about the Bootcamp from last year… thank you old friend.

Better focus and produce some results.

How can my Mandarin suck so bad!!! Argh.

do..while loops execute at least once, before the condition is evaluated

for (const value of list) {

“We can declare it as a const because in every iteration the scope is re-initialized.”

ahhhh how do you do this, how do you explain things right when a question shows up, does this make the student/reader lazy? perhaps?

“This operator has some pretty useful applications. The most important one is the ability to use an array as function argument in a very simple way”

THIS! HA!

Polyfill.

“The cool thing about this operator is that the second expression is never executed if the first evaluates to false.”

“This is because var declarations are hoisted and initialized with undefined as a value, while const and let are hoisted but not initialized.”

Hoisting > 移上去

Var > function scope

Const, Let > block scope

Use strict mode by default

Immediately-invoked Function Expression

don’t pollute the global object

isolate variables declarations

(function() {
/* */
})()

“We basically have a function defined inside parentheses, and then we append () to execute that function: (/* function */)().”

The main difference between a function expression and a function declaration is the function name, which can be omitted in function expressions to create anonymous functions. A function expression can be used as an IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined.

An expression evaluates to a value. A statement does something.

In JavaScript, parenthesis cannot contain statements; it can only contain an expression.

;(function() {
/* */
})()

Fixes the issue of the second opening parenthesis.

model: "Fiesta",

drive() {

“Note: the above method declaration is the same as drive: function() {…, but shorter:”

YES.

regular function > bound

arrow function > not bound

Automatic Semicolon Insertion…

It’s always something in the background that goes wrong lol

When there is a return statement on its own line… that’s why { is always after return? always thought it was a style thing

Flavio is so good at giving examples

I think this is also something I can improve on, to create examples that DON’T WORK…

“Important: the UNIX timestamp reasons in seconds. JavaScript dates reason in milliseconds.”

Serialization. I like how Flavio explains this. Would have been useful 3 years ago lollll

“Any other data type that’s more complex than this must be serialized to a string (and then de-serialized) in order to be stored in JSON.”

Important : If a key-value pair passing through this reviver method causes an error or the reviver method returns “undefined” for any pair, then that key-value pair is dropped from the final parsed JSON object.”

https://usefulangle.com/post/112/json-parse-reviver-function#:~:text=This%20optional%20second%20parameter%20is,value%20pair%20before%20being%20returned.

“It’s either absolute, or has a ./ or / before the name.”

finally

try {
//lines of code
} finally {

}

“Browsers create an event loop for every browser tab”

“Promises that resolve before the current function ends will be executed right after the current function.”

Then

“So what happens if the delay is set to 0? A new message is added to the queue immediately, and will be processed when the currently executing code is finished and any previously-added messages have been processed.”

https://stackoverflow.com/questions/33955650/what-is-settimeout-doing-when-set-to-0-milliseconds#:~:text=So%20what%20happens%20if%20the,added%20messages%20have%20been%20processed.

The reason we can do more than one thing is because the browser is more than runtime.

Event loop checked that the stack is clear and there’s a callback on the task queue.

So why do you want to run the function in zero time?

Generally, if you want to defer something until the stack is clear.

“When people say don’t block the event loop, they’re saying don’t put shitty slow code on the stack.”

Ok. So that first one from Philip Roberts was in 2014 but really good video. Great speakers really help you understand the world a bit more.

This second one is from Jake Archibald in 2018 and right at the start of the talk he tells us he uses semi-colons lolll (and says the rest are monsters, joking of course)

lol

Running tests with JS will probably be different as a user clicking.

Sign up to discover human stories that deepen your understanding of the world.

Chunhao Weng
Chunhao Weng

Written by Chunhao Weng

Random notes for personal use.

No responses yet

Write a response