Benben
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # [JS101] 用 JavaScript 一步步打造程式基礎 ###### Date : 2021 Apr. 16 - 2021 Apr. 22 - node.js 讓 Javascript 跑在瀏覽器以外 - 等於 (== & ===) 的誤區三本柱 ( 0, null, undefined) ```javascript > 0 == null // false > 0 == undefined // false > null == undefined // true > null === undefined // false ``` ![](https://i.imgur.com/ElH0YOol.png) > 上廁所時,可以好好思考🤣🤣🤣 - bool style guide ```javascript // good var score = 60; var isPass = score >= 60; // bad var score = 60; var isPass = false; if (score >= 60) { isPass = true; } else { isPass = false; } ``` - 三元判斷式 Ternary ```javascript console.log( 10 > 5 ? 'yes' : 'no') // yes var score = 60; var isPass = score >= 60 ? 'pass':'fail'; ``` - 善用 Chrome 的 debugger - 使用匿名函式 ( anonymous function ),增加效能 - 參數 ( parameter ) & 引數 ( argument ) 引數 ( argument ) 為 Javascript 特有的,可以在 function 裡使用 ` argument[i]` 呼叫使用,很少用到,但實際上 argument 為 Object 非 Array。 - Array.sort() 原理 ```javascript var arr = [1, 30, 4, 21]; arr.sort(function(a, b){ if(a === b) return 0 // -1 表示兩者不換位置 if(b > a) return -1 // 1 表示兩者換位置 return 1 }) console.log(arr); // 1, 4, 21, 30 ``` - Array 的 metheds : slice, splice 有點搞混,以下整理 > slice(start, end) ,取出子矩陣。 > splice(start, number, replce), 修改、刪除元素。 ```javascript let arr1 = [1, 2, 3, 4]; let arr2 = [1, 2, 3, 4]; let arr3 = [1, 2, 3, 4]; let arr4 = [1, 2, 3, 4]; arr1.slice(2, 4); console.log(arr1); // [1, 2, 3, 4] arr2 = arr2.slice(2, 4); // *Use this slice* console.log(arr2); // [3, 4] arr3.splice(2, 1); // *Use this splice* console.log(arr3); // [1, 2, 4] arr4 = arr4.splice(2, 1); console.log(arr4); // [3] ``` - Array 的 metheds : map ```javascript ['1', '2', '3'].map(parseInt); // 以為會是 [1, 2, 3] 嗎 // 其實是 [1, NaN, NaN] function returnInt(element) { return parseInt(element, 10); } ['1', '2', '3'].map(returnInt); // [1, 2, 3] ['1', '2', '3'].map( str => parseInt(str) ); // [1, 2, 3] ['1', '2', '3'].map( str => Number(str)); // [1, 2, 3] ['1', '2', '3'].map(Number); // [1, 2, 3] // but unlike `parseInt` will also return a float (浮點數) or (resolved) exponential notation (科學記號) : ['1.1', '2.2e2', '3e300'].map(Number); // [1.1, 220, 3e+300] ['1.1', '2.2e2', '3e300'].map( str => parseInt(str) ); // [1, 2, 3] , 整數的 `.` 或 `e` 後面直接被捨去 ``` - Array(n) 可產生 n 個空陣列 ```javascript arr = Array(5); // [ , , , , ] arr = Array(5).fill(0); // [0, 0, 0, 0, 0] ,搭配 fill 產生元素均為 `0` 的 n 陣列 arr = Array(5).fill(0).map( (e, idx) => idx + 1); // [1, 2, 3, 4, 5] ,搭配 map 產生 1 ~ n 的陣列 ``` - Immutable (不可改變型態) 觀念 ```javascript var arr = 'hello'; arr.toUpperCase(); console.log(arr); // hello var arr = 'hello'; arr = arr.toUpperCase(); console.log(arr); // HELLO ``` #### 延伸 : 請分別說明以下輸出是甚麼,並試著解釋 ``` console.log('hello' ? true : false); console.log('hello' == true); console.log('hello' == false); ``` #### Ref. - [浮點數 floor](http://blog.dcview.com/article.php?a=VmhQNVY%2BCzo%3D) - [MDN : 引數 Arguments](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Functions/arguments) - [MDN : Array Map](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/map) - [深入探討 JavaScript 中的參數傳遞:call by value 還是 reference?](https://blog.techbridge.cc/2018/06/23/javascript-call-by-value-or-reference/) - [JavaScript 資料結構及演算法實作 (暢銷回饋版)](https://www.tenlong.com.tw/products/9789864343522) --- #### 心得 ###### 2021 Apr. 22 這門課基本上都兩倍速看,可能因為前面基礎還可以,我知道也有很多有基礎的同學是跳著看甚至沒看得,但我還是堅持至少全部看過一輪,因為我認為 : **huli 老師這麼強的高手都願意再講一次了,我為什麼不願意再聽一次?** 而且絕對有你還沒熟悉的基礎,就算熟悉了,聽聽看 huli 老師是怎麼講解的這個觀念的,感覺又不一樣,受益良多。 練習題 25 題都解完了,都可以在不看解答的情況寫完,寫完之後再跟老師對答案,沒什麼大問題,也學到很多胡立老師的思考過程,很讚,對我來說這門課算是熱身,之後準備衝囉 GO GO GO

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully