DanKim0213 / Today-I-Learned

Today I Learned
1 stars 0 forks source link

JavaScript #12

Open DanKim0213 opened 1 year ago

DanKim0213 commented 1 year ago

JavaScript

Javascript concept hierarchy I referred to MDN javascript guide

Hierarchy

TODO list

DanKim0213 commented 1 year ago

Things to complement

DanKim0213 commented 1 year ago

statement vs declaration "You can see declarations as "binding identifiers to values", and statements as "carrying out actions"."

DanKim0213 commented 10 months ago

Hoisted with let or const variables?

"All declarations (var, let, const, function, function*, class) are "hoisted" in JavaScript."

JavaScript has the following kinds of scopes:

In addition, variables declared with let or const can belong to an additional scope:

References

DanKim0213 commented 7 months ago

Arrow function

MDN TODO:

setTimeout in MDN

class Hello {
  constructor() {
    this.name = "semi";
  }

  bloom() {
    // this.declare();
    // by default, `this` within setTimeout is globalThis.
    // setTimeout(this.declare.bind(this), 1000);
    setTimeout(() => this.declare(), 1000);
  }

  declare() {
    console.log("hoi hoi", this.name);
  }
}

const hello = new Hello();
hello.bloom();

Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods:

TODO: However, because it is a closure, not the function's own binding, the value of this will not change based on the execution context.

Arrow function properties are often said to be "auto-bound methods", because the equivalent with normal methods is:

DanKim0213 commented 7 months ago

Event Loop

According to MDN - Event Loop:

JavaScript has a runtime model based on an event loop, which is responsible for executing the code, collecting and processing events, and executing queued sub-tasks.

https://www.javascripttutorial.net/javascript-event-loop

DanKim0213 commented 7 months ago

Closures

DanKim0213 commented 7 months ago

What is JavaScript

https://www.javascripttutorial.net/what-is-javascript/ https://www.javascripttutorial.net/javascript-event-loop/

JavaScript is a single-threaded programming language. This means that JavaScript can do only one thing at a single point in time.

DanKim0213 commented 4 months ago

New keyword

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new#description