Skip to content

Instantly share code, notes, and snippets.

View showlovezz's full-sized avatar

vita hsieh showlovezz

  • Taiwan
View GitHub Profile
@showlovezz
showlovezz / scope.js
Last active February 9, 2020 13:14
鼠年全馬鐵人挑戰 - 1-1
var status = 'failed'; // 全域變數
function getStatus() {
var status = 'ok'; // 區域變數
return status
}
console.log(getStatus())
console.log(status)
// 從第一行到第七行稱為全域範圍
// 從第二行到第五行稱為區域範圍
@showlovezz
showlovezz / whyVar.js
Last active February 9, 2020 13:29
鼠年全馬鐵人挑戰 - 1-2
status = 'failed'; // 全域變數
function getStatus() {
status = 'ok'; // 區域變數
return status
}
console.log(getStatus()) // 印出 ok
console.log(status) // 預期要印出 failed,結果卻印出 ok
@showlovezz
showlovezz / hostingVar.js
Last active February 9, 2020 13:41
鼠年全馬鐵人挑戰 - 1-3
console.log(status)
var status = 'failed';
function getStatus() {
console.log(status)
var status = 'ok';
return status
}
// 第一行會印出 failed
// 第四行會印出 undefined (未定義)
@showlovezz
showlovezz / sampleLet.js
Last active February 9, 2020 15:21
鼠年全馬鐵人挑戰 - 1-4
function vipName() {
let customer = 'Acer'
}
console.log(customer) // 會出現 customer is not defined
function cityName() {
const city = 'Taipei'
}
console.log(city) // 會出現 city is not defined
@showlovezz
showlovezz / sampleBlock.js
Last active February 9, 2020 15:32
鼠年全馬鐵人挑戰 - 1-5
var x = 1;
{
var x = 2;
console.log(x)
}
console.log(x)
// console 會印出 2 跟 2
let x = 1;
{
@showlovezz
showlovezz / baseArrow.js
Created February 15, 2020 16:17
鼠年全馬鐵人挑戰 - 2-1
(參數,...) => {
程式敘述;
return value
}
@showlovezz
showlovezz / sampleArrow1.js
Created February 15, 2020 16:36
鼠年全馬鐵人挑戰 - 2-2
const mathDouble = function(a) { // 函式表達式
return a * 2;
}
console.log(mathDouble (10)) // 呼叫函式
@showlovezz
showlovezz / sampleArrow2.js
Created February 15, 2020 16:40
鼠年全馬鐵人挑戰 - 2-3
const mathDouble = (a) => { // 箭頭函式表達式寫法
return a * 2;
}
console.log(mathDouble (10)) // 呼叫函式
@showlovezz
showlovezz / sampleArrow3.js
Created February 15, 2020 16:53
鼠年全馬鐵人挑戰 - 2-4
const mathDouble = (a) => a * 2;
@showlovezz
showlovezz / sampleArrow4.js
Created February 15, 2020 17:03
鼠年全馬鐵人挑戰 - 2-5
const vipName = (acer) => console.log('Welcome' + acer);
const vipName = acer => console.log('Welcome' + acer); // 只有一個參數,可以不用加上括號
const vipName = () => console.log('Welcome'); // 沒有參數,括號必須保留