# 第二週共筆筆記 - <br> 10/12 核心篇第二堂:表達式、陳述式 ###### tags: `核心篇`、`六角學院`、`2022JS直播班` ### 共筆簽到區 Data XYY Barret ### 正課開始!~~~~ ```javascript var a = 1 if (a = 2) { console.log(1); // 這一個數字 1,會不會出現 } ``` 一個等號是賦值 if 判定是當中,值要()為True 就會執行 ```javascript let a = 1; console.log(++a +1); ``` 答案是3 ++a 是先運算後,在賦值給a ### 什麼是表達式 expressions 表達式又稱運算式 任何有結果的,都可以稱為表達式 1. 任何的純值、變數 ``` var a = 1; ``` 2. 搭配運算子 ```javascript console.log( a === 1); console.log(a || 1); 兩者有1則為1 console.log(0 && 1); 兩者有0則為0,兩者都1則為1 ``` 3. 執行函式 ``` javascript function fn(){ retuen; } fn(); console.log(fn()); ``` 4. ### 什麼是陳述式 statements 陳述式與宣告 * 陳述式語句比較好了解 * 陳述式不一定式多行,其中可能混和表達式。 ```javascript var a = 1; 陳述式 var a; 陳述式 a = 1; 表達式 ``` * 判斷陳述式,要看完整結構。 if(條件式) { 條件式 也expression 表達式的一種 statement1 } 1. 宣告 ```javascript var a = 1; let b = 2; const c = 3; function name(params){ } ``` 2. 流程控制 ```javascript if(a){ } ``` ``` javascript { const a = 1; } ``` 3. 迴圈 for 4. import, export ##### 陷阱,判斷是 陳述式 還是 表達式 ``` delete x; ``` ans: 是表達式, 因為 delete 是運算子 1. 函式陳述式(定義) ```function 作為宣告使用、必須有一個名字 具名函式 function callFunction(){} callFunction(); console.log(callFunction); ``` 2. 函式表達式 2-1. ```javascript const fn = function(){ console.log("沒有名字,所以為匿名函式"); } fn(); ``` ```javascript const fn = fn2(){ console.log(fn2,'具名函式'); } fn(); console.log(fn); ``` 建立一個函式,然後賦予給前面變數 fn ```javascript fn 是 變數名稱 fn2 是 函數名稱 函數具名最好的功能是,拿除錯用 ``` 2-2. 立即函式 如果沒有名字,就不好除錯 ```javascript (function(){} )(); ``` 2-3. 箭頭函式 ```javascript const a = () => { } (() =>{ return '123456'; })(); //立即函式、執行函式 ``` 2-4 閉包、高階函式 測驗 ```javascript if(function()) ``` 等號運算子 ```js const obj = { value: 1, } Object.defineProperty(obj, 'value', { writable: false }); obj.value = 0; console.log(obj.value); const b = obj.value =2; console.log(b); ``` 優先性 ```js console.log(1 < 2 < 3); console.log(1 < 2); // 1. true console.log(true < 3); // 2. true // console.log(3 > 2 > 1); console.log(3 > 2); // 1. true console.log(true > 1); // 2. false ``` 題型 ```json //只有考試會出現的題型 console.log(a++); //1 console.log(a); //2 // console.log(++a); // const b = ++a +1 ; console.log(b); //3 // const b = a++ +1 ; console.log(b); //2 // var b = a++ + 1; var c = a * 10; console.log(b); console.log(a); ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up