學 JavaScript 的那些筆記


一句話說明 Node.js

Node.js 是一個 JavaScript 的建置環境(runtime environment),讓 JavaScript 可以在你的電腦跑。

Node.js 官網下載,即可擁有

一些簡單的操作

  • 查看是否下載好了:node -v
  • 建一個檔案(ex.html 或 JavaScipt)然後編輯:vim index.html vim index.js
  • 印出檔案裡面的東西(ex. index.js):node index.js
  • 跳出 Node:.exit

位元運算子(二進位)

>>:右進位,乘以 2 的幾次方
<<:左進位,除以 2 的幾次方
舉例:

10 << 1 //10 * 2 = 20
10 << 3 //10 * 2 * 2 * 2 = 80
9 >> 1 //9 / 2 = 4
13 >> 1 //13 /2 = 6

&:and (&& 是邏輯運算)
|:or (|| 是邏輯運算)
^:xor
~:not
舉例:

10 & 15 //回傳 10,1010 and 1111 = 1010
10 | 15 //回傳 15,1010 or 1111 = 1111
10 ^ 15 //回傳 5,1010 xor 1111 = 0101 兩個一樣傳 0,不一樣傳 1
~ 15 //回傳 -16,not 1010 = 0101


關於變數

var:想樣成一個箱子,可以存東西在裡面,可以幫箱子命名
++aa++ 的差別:前者先處理 ++,後者後處理 ++

var a = 0
console.log(++a && 30)
=> 
a +=1
console.log(a && 30)
====
console.log(a++ && 30)
=> 
console.log(a && 30)
a += 1


變數型態

typeof 看變數型態,總共六種

  • boolean:true or false
  • string:字串
  • number:數字
  • object:物件
  • undefined:未定義
  • function:函式

看看======的差異
=:賦值 (ex. var a = 1,把 a 賦予 1 值)
==:比較相等 (ex. 10 == 10,true;10 == "10",true)
===:比較相等,還多比較型態是否相等(ex. 10 === 10,true;10 === "10",false)

#javascript #Web #notes






你可能感興趣的文章

React 實戰篇 - 部落格

React 實戰篇 - 部落格

[13] 物件導向 OOP - Class

[13] 物件導向 OOP - Class

Visual Studio Code (VS Code) 設置全域ESLint

Visual Studio Code (VS Code) 設置全域ESLint






留言討論