凱文_hws
    • 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
    # 執行環境與詞彙環境 ## Syntax parsers 語法解析器 A program that reads your code and determines what it does and if its grammar is valid. Your code isn't magic. Someone else wrote a program to translate it for the computer. ![](https://i.imgur.com/yAxd60a.png) ## Execution contexts 執行環境 - A wrapper to help manage the code that is running. - There are lost sof lexical environments. Which one is currently running is managed via execution contexts. It can contain things beyond what you've written in your code. ## Lexical environment 詞彙環境 - Where something sits physically in the code you write - "Lexical" means 'having to do with words or grammar'. A lexical environment exists in programming languages in which where you write something is important. - 如果提到這個,意思是在討論它被寫在哪裡? 它的周圍環境是甚麼? ## Name/value Pair - A name which maps to a unique value - The name may be defined more than once, but only can have one value in any given context. That value may be more name/value pairs. - ![](https://i.imgur.com/YancReW.png) ## Object - A collection of name value paris - The simplest definition when talking about **Javascript** - ![](https://i.imgur.com/QzmNJH5.png) - ![](https://i.imgur.com/eBDJraF.png) ## The global environment and the global object ### Global、this 是 Javascript 引擎自動幫你生成的 - Glogal means "Not inside a Function" - Javascipt 的 Global 是 window,node 的 global 是別的東西。 - outer environment - ![](https://i.imgur.com/arrWs2G.png) ## The execution context: Creation and hoisting Execution Context 被分為兩階段創造,第一階段是創造(creation)階段,這個階段會產生 Global Object, 'this', Outer Environment 最後會 Steup memory space for Variables and Functions(這就是 Hoisting)。 表示在執行程式碼之前已經為變數與函數在記憶體中創造空間,所以當程式被逐行執行時,它可以找到它們。 不過變數的情況有點不同,變數都會先被指定為 "undefined",然後在執行的時候才會被附值,而函式則會被完整儲存起來。 ## Undefined - Javascript 在創造執行環境的第一階段時會為變數設定初始值 `undefined`,如果是一個未曾被設定為初始值的東西則會得到錯誤訊息 `Uncaught ReferenceE: something is not defined`,因為它沒辦法在已經創造的記憶體之中找到這個東西。 - `undefined` 是一個特殊關鍵字,它是一種值,會是創造階段的變數之預設值。 - 永遠不要設定任何東西為 `undefined`,將會有幫助你除錯,只要一看到 `undefined` 時就可以理解為不曾為其附值 ## Execution Context Runs code (Execution phase 執行階段) 逐行執行 ## Single threaded & synchronous execution - (單執行緒、同步執行),Javascript 是單執行緒、同步執行的 - Single threaded - One command at at a time - Under the hood of the browser, maybe not,但從我們的角度來說 Javascript 是單執行緒的 - Synchronous execution - One at a time - And in order ## Invocation Running a function In javascript, by using parenthesis () ## Variable environment Where the variables live. And how they relatve to each other in memory ## scope chain - Javascript 會依照 Lexical environment 來尋找變數 (此例是尋找變數),從該 Execution contexts 開始往外面找 outer reference - 每個 Execution contexts 都會有 outer reference (此例的 function a 的 outer reference 是 global) - 與函式呼叫的位置沒有關係。 ```javascript= function a(){ console.log(myVar) // 1 } function b(){ var myVar = 2 a() } var myVar = 1 b() ``` ## Scope - Where a variable is available in your code - And if it's truly the same variable, or a new copy ## let - Can be use instead of var - Allow JavaSciprt engine to use block scoping - During the execution phase where it's created, the variable is still placed into memory and set to `undefined`. Hoever, you're **NOT** allowed to use let until the lin of code is run. - When `let` is declared inside the block, it's only available inside that block at that period of time for the running code. ## Asynchoronous more than one at a time ![](https://i.imgur.com/ohCQoGG.png) JavaScript 會先執行 execution stack 的 event,等到完成之後才會去執行 event queue,等到結束時,會持續查看 event queue 的迴圈,這個過程稱為 continuous check。 在 Javascript 提到的非同步其實是在 Javascript 外的引擎執行的,Javascript 本身是同步的。 ###### tags: `WierdJavascript`

    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 Google 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