2-13 Single thread, Synchronous execution

bigword alert : single thread

  • one command at a time
  • under the hood of the brower, maybe not

bigwod alert : synchronous

  • one at a time, and in order

講師霸氣的說:現在先相信我,js是 single thread, synchronous

Comment and share

2-12 Code execution

Recall : two phases to run a js code

  1. creation phase : set up global object , setup variables, outer environments …
  2. execution phase : execution the code “line by line”

Comment and share

2-11 Undefined

千萬不要自己將變數的值設成undefined,以保證undefined都是js engine 所設的,方便debug

作者覺得叫notset 比較合適 😤

1
2
3
console.log(a);

//Uncaught ReferenceError: a is not defined
  • a does not exist in memory
1
2
3
4
5
var a;

console.log(a);

//undefined
  • a exists in memory, but is set to a special value - undefined
testing undefined value
1
2
3
4
5
6
7
8
9

var a;

if (a === undefined){
console.log("a is not defined");
}
else{
console.log("a is definded");
}

Comment and share

2-10 Creation and hoisting

  • hoisting : before js code is run line by line, js engine set memory space for the variables
  • all variables is initialized to undefined in js

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

b();
console.log(a);

var a = 'Bello';
function b (){
console.log('called b');
}
/*
called b
undefined
*/
1
2
3
4
5
6
7
8
9
10
11
12

b();
console.log(a);

function b (){
console.log('called b');
}

/*
called b
Error!!
*/

Comment and share

Author's picture

Necisam

author.bio


author.job


Tainan, Taiwan