Two types of database
Relational Database
Consists of 2 or more tables with columns and rows
The relation between tables and fields is called a schemaforeign key
primary key
Use SQL to communicate with the server
MySQL, PostgreSQL
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
函式參數 (parameters) vs. 函式引數 (arguments)
先上 MDN 的說明:
參數 parameter:A parameter is a named variable passed into a function. Parameter variables are used to import arguments into functions.
引數 argument:An argument is a value (primitive or object) passed as input to a function.
「函式參數(parameters)」是定義函式時所列出的變數,用來將引數導入至函式中;「函式引數(arguments)」則是實際上輸入至函式或是函式收到的值。
// 定義函式,設定「參數」
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
Scope 作用域
什麼是作用域
「作用域就是一個變數的生存範圍,一旦出了這個範圍,就無法存取到這個變數」。
當我們把變數 a 宣告在 function 中,function 之外的地方都無法取用這個變數:
// 把變數宣告在 function 中
function test1() {
var a = "hello"
}
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
Block elements vs. Inline elements
區塊元素 block element
display: block
盡可能佔滿整個版面(依照父元素的寬度)
可以設定寬、高:應避免寫死高度,實際高度應由裡面元素的高度推擠而來
另起一行呈現
常見的區塊元素標籤:
<div>:沒有語意,單純拿來排版的標籤
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
什麼是 NaN
NaN(Not a Number) 顧名思義就是非數字
NaN 的型別是 Number: typeof NaN // Number
NaN 不等於任何值,也不等於自己NaN === NaN // false
typeof NaN // number
NaN === NaN // false
:::info
備註:在 IEEE 754 的規範中就有定義如果判斷式遇到 NaN 就要回傳 false
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
Null, undefined, not defined 差異
null 與 undefined 差異
null 代表「空值」(有被賦予為空的值),轉為數值時為 0;undefined 代表「未定義」的原始值(尚未被賦予值),轉為數值時為 NaN
undefined 與 not defined 差異
undefined 是變數被宣告了但沒有賦值,屬於原始型別之一;not defined 是變數沒有被宣告,不屬於原始型別,是執行程式時的錯誤訊息 (runtime error),需要被修正。
console.log(a) // 會報錯:Uncaught ReferenceError: a is not defined
var a
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
this 是什麼
this 是 JavaScript 的一個關鍵字
this 是 function 執行時,自動生成的一個內部物件
隨著 function 執行場合的不同,this 所指向的值,也會有所不同
this 與 function 在何處被宣告完全無關,而是取決於 function 被呼叫的方式
在大多數的情況下, this 代表的就是呼叫 function 的物件 (owner Object of the function)當 function 是某個 object 的 method,this 指的就是上層物件
this 的指向(綁定規則)
默認綁定 Default Binding
當 function 被呼叫的當下如果沒有值或在 func.call(null) 、func.call(undefined) 這類的情況下,此時 function 裡的 this 會自動綁定至全域物件:
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
https://www.npmjs.com/package/express
One of the most popular libraries to build server with node.
:::info
Ref. The State of JavaScript Developer Survey
:::
Install
$ npm install express
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
Node comes with its own http built-in module
using http module
const http = require('http'); // grab the 'http' module
const server = http.createServer( ()=> {
//console.log('headers', request.headers)
console.log('method', request.method)
console.log('url', request.url)
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark
Node.js
https://nodejs.org/en/
allows us to run Javascript outside the browser
Node.js is created using the V8 engine to read and run JS outside the browser
popular for building servers
Install Node.js
Install
https://nodejs.org/en/download/
Hsieh Ya Chu changed 2 years agoView mode Like Bookmark