grayshine
    • 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

      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.
      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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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

    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.
    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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # <font class="h2">何謂表達式(Expression)與陳述式(Statement)?</font> ###### tags: `javascript` <style> .h2 { background: linear-gradient(135deg,#fff,#537479) ; color: #537479; display:block; padding: 6px 5px; border-radius: 4px; } .h3 { background: linear-gradient(180deg,#fff 50%,#c9d5d4) ; color: #537479; display:block; padding: 6px 5px; border-bottom: 3px solid #537479; } .h4 { color: #537479; font-weight:bold; font-size:1.1em; } </style> JavaScript 有兩種語法分類:陳述式與表達式。 表達式、陳述式、區塊它們都是語法容器 陳述式會執行動作、表達式會回傳某值 ### <font class="h4">➤陳述式 Statement</font> 陳述式可能是幾個單詞或是一個片段(但不會是單一個字母) 陳述式一定會做一些事情,最大的特徵則是==不會回傳結果== 常見如下: - 宣告(var、let、const、function) - 流程控制(block`{}`、if…else、switch) - 迴圈(for、for…in、while) - 其它(import, export) <br> 區塊陳述 ( Block Statement ) `{}`block裡面的是表達式(Expression),像是 if 的區塊一樣,在裡面會執行一些動作,但執行完成後也不會回傳任何數值,是屬於陳述式。 如果我們僅有使用 `{}` 這個意思是「物件」,這不會是一個陳述式,必須在其中加入一些片段程式碼才會是陳述式 :::info ==陳述式(Statement)不能賦值給一個變數== 陳述式不會產生數值,所以不能被放在 JS 內預期會產生數值的地方,例如「函式的參數」、「函式的回傳值」、或是「宣告變數」時等號的右邊(不能分配給另一變數)。 例: ```javascript ming = if(1 === 1){}//會報錯 ``` <br> 此為函式陳述式,不可以賦值給變數 ```javascript { var ming = '小明'; } //如果將它賦值給變數就會報錯 ``` ```javascript var a = { var ming = '小明'; } //會報錯 ``` <br> 此為物件實字,可以賦值給變數 ```javascript { ming: ‘小明’ } //可以賦值給變數 ``` ```javascript var a ={ ming: ‘小明’ } //不會報錯 ``` ::: <br> ### <font class="h4">➤表達式Expression</font> 又可稱為表示式、運算式,經常透過一些符號(運算子)結合上下語句並運算及==回傳結果== 表達式是一段可以很長,也可以很簡短,只要是執行後會回傳結果的,就是表達式。 ==「等號」是一個表達式。(所有的運算子都是表達式)== 常見如下: - 純值 - 變數 - 運算子 - 執行函式 - 正規表達式 - 函式表達式 :::info 表達式範例: ```javascript //呼叫函式 functionInvocation() //變數指派 a = 3 //運算式 1 + 2 a === 3 ture || false d true && true Array.isArray([]) ? doSomeThing() : doOtherThing() ``` ::: <br> 表達式可以獨立出現,也可與陳述式混合使用。 ![](https://i.imgur.com/BZESB4P.png =500x) ![](https://i.imgur.com/XFipbv2.png =500x) <br> ### <font class="h3">函式</font> JS的函式宣告,根據不同的方式可以是「宣告式」也可以是「表達式函式」 ### <font class="h4">➤函式陳述式(具名函式)</font> 函式陳述式是藉由直接給定名字來直接宣告一個函式。 ```javascript function callName(){ } ``` ### <font class="h4">➤函式表達式(匿名函式)</font> 是把一個匿名函式指派給一個變數,之所以能夠這麼做是因為函式本身在javascript裡面也是一種物件,所以除了一般的宣告方式外,函式也能夠作為一個被指派的值。 ```javascript var callName = function(){ } ``` 這種宣告方式的函式內容不會在一開始就被提升,會被提升的只有該變數而已。在執行階段,才會把函式內容指派給變數 :::info 函式陳述式(具名函式)、函式表達式(匿名函式)兩者hoisting會不同 :arrow_right:[hoisting拉升](https://hackmd.io/@grayshine/rk9hv-TBt) ::: <br> --- https://wcc723.github.io/development/2020/09/17/js-expression/ https://ithelp.ithome.com.tw/articles/10218937 https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Statements

    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

    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

    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