EddyYeh
    • 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
    # 面試考古題Review ## 1. 請說明var, let, const差異 ### 1.1 var: 1.變數作用域:全域&函式 2.變數一般沒宣告會referenceError,若先宣告var a,會有 ![](https://hackmd.io/_uploads/S1ReyndHh.png) 3.在全域範圍或函式內聲明的變數將被提升(hoisted),意味著它們在宣告之前就可以被訪問。 ![](https://hackmd.io/_uploads/ryi4g3dHn.png) ### 1.2 let: 1. let 宣告的變數的作用域是區塊範圍(區塊是由花括號 {} 定義的程式碼片段)。 2. 在同一作用域內,不允許重複聲明同名變數。 3. 不會被提升,必須在聲明後才能訪問。 4. 可以重新賦值,但不能重新聲明。 ### 1.3 const 1. 作用域規則與 let 相同,是區塊範圍。 2. 必須在聲明時初始化。 3. const 創建的是一個對象的引用,因此對於引用類型的變數,不能修改變數指向的記憶體地址,但可以修改該對象本身的屬性。 4. 宣告的是一個常量,其值在聲明後不能被修改。 ### 1.4 結論 ![](https://hackmd.io/_uploads/HJZN-3uB2.png) ## 2 請說明以下兩段sql何者效能較優?邏輯為何? 第一段: ```sql= select * from user where age = 10 ``` 第二段: ```sql= select a.* from user a inner join( select id from user where age = 10 ) b on b.id = a.id ``` ### 2.1 答 第一段這個查詢是直接在 user 表中搜尋滿足條件 age = 10 的所有行。它將掃描整個 user 表,並返回符合條件的結果。這個查詢在一個簡單的條件下可能不會有太大的效能問題,但如果 user 表非常大且沒有適當的索引,或者有其他複雜的條件和連接,則可能會導致效能下降。 ### 2.2 答 這個查詢使用了內部查詢(subquery)和內部連接(inner join)。首先,在內部查詢中,只選擇 user 表中符合條件 age = 10 的 id 值。然後,外部查詢中的內部連接將這些 id 值與原始 user 表進行連接,只返回匹配的行。 這種方式可以利用索引(如果存在)來快速獲取滿足條件的 id 值,並且只連接需要的行。它可以有效地減少掃描整個 user 表的需要,因此在大型表或具有複雜條件的情況下,效能通常較好。 總體而言,第二段查詢在這種情況下效能較優,因為它使用了內部查詢和內部連接,可以減少掃描和連接的行數。但是,實際效能還受到數據量、資料庫結構和索引的影響,因此在實際應用中,仍應根據具體情況進行評估和測試。 ![](https://hackmd.io/_uploads/rJ97X2Orh.png) ## 3. 寫出一條SQL語句:取出表中第31到第40筆,共10筆紀錄 (Primary Key為ID,但ID不是連續的) ```sql= SELECT * FROM ( SELECT * FROM table_name ORDER BY ID LIMIT 40 ) AS subquery ORDER BY ID DESC LIMIT 10; ``` ## 4.請說明個輸出為何 ```csharp= public class Numbers { public int n1 = 0; } static void Main(string[] args) { Numbers numbers = new Numbers() { n1 = 2 }; ChangeNumber(ref numbers.n1); Console.WriteLine(numbers.n1); ChangeNumber(numbers.n1); Console.WriteLine(numbers.n1); ChangeNumber(numbers); Console.WriteLine(numbers.n1); ChangeNumber(ref numbers); Console.WriteLine(numbers.n1); Console.ReadLine(); } static void ChangeNumber(int innerNumber) { var result = innerNumber + 3; } static void ChangeNumber(ref int innerNumber) { var result = innerNumber + 3; } static void ChangeNumber(Numbers innerNumber) { innerNumber = new Numbers(); innerNumber.n1 = 5; } static void ChangeNumber(ref Numbers innerNumber) { innerNumber = new Numbers(); innerNumber.n1 = 5; } ``` ### 4.1 答:2.2.2.5 ## 5 實作中,有時候會將某個物件作為Template使用,為了避免後續的操作造成Template的改變,我們需要複製物件來使用。 請實現一個深成複製(Deep Cline)的函式,可以對Object, Array, Number, String等資料型別進行複製 分別以c# 和 javascript呈現 ## 5.1 答javascript ```javascript= function deepClone(obj) { if (obj === null || typeof obj !== "object") { return obj; } let clone; if (obj instanceof Array) { clone = []; for (let i = 0; i < obj.length; i++) { clone[i] = deepClone(obj[i]); } } else if (obj instanceof Object) { clone = {}; for (let key in obj) { if (obj.hasOwnProperty(key)) { clone[key] = deepClone(obj[key]); } } } else { clone = obj; } return clone; } let originalObject = { /* ... */ }; let clonedObject = deepClone(originalObject); ``` ## 5.2 答c# ```csharp= using System; using System.IO; using System.Runtime.Serialization.Formatters.Binary; public static class DeepCopyHelper { public static T DeepClone<T>(T obj) { if (obj == null) return default(T); using (MemoryStream stream = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, obj); stream.Seek(0, SeekOrigin.Begin); return (T)formatter.Deserialize(stream); } } } MyObject originalObject = new MyObject(); MyObject clonedObject = DeepCopyHelper.DeepClone(originalObject); ``` ## 6. 寫一段程式排除陣列重覆值 ```csharp= using System; using System.Collections.Generic; public static class ArrayHelper { public static T[] RemoveDuplicates<T>(T[] array) { if (array == null) return null; HashSet<T> uniqueValues = new HashSet<T>(array); T[] result = new T[uniqueValues.Count]; uniqueValues.CopyTo(result); return result; } } int[] numbers = { 1, 2, 3, 4, 3, 2, 5 }; int[] uniqueNumbers = ArrayHelper.RemoveDuplicates(numbers); Console.WriteLine(string.Join(", ", uniqueNumbers)); // 輸出: 1, 2, 3, 4, 5 ``` ## 7. 請解釋以下程式碼,輸出結果。請解釋程式碼運作原理 function makeAdder(x) { return function(y) { return x + y; }; } var add5 = makeAdder(5); console.log(add5(2)); // 7 ChatGPT ### 7.1 答 這段程式碼展示了一個使用 JavaScript 閉包(Closure)的概念。讓我們逐行解釋: javascript Copy code function makeAdder(x) { return function(y) { return x + y; }; } 這個 makeAdder 函式接受一個參數 x,並返回一個新的函式。這個新的函式是一個匿名函式,它接受參數 y,並返回 x + y 的結果。由於閉包的特性,它可以記住外部函式 makeAdder 中的變數 x。 javascript Copy code var add5 = makeAdder(5); 在這一行中,我們呼叫 makeAdder 函式並將 5 作為參數傳遞給它。makeAdder(5) 的結果是一個新的函式,並將其賦值給變數 add5。 這個新的函式可以被視為一個「加法器」,它記住了在 makeAdder 中傳入的 x 值,並可以將它與後續傳入的 y 值相加。 javascript Copy code console.log(add5(2)); // 7 在這一行中,我們呼叫 add5 函式並將 2 作為參數傳遞給它。由於 add5 是由 makeAdder(5) 返回的函式,因此它可以記住在 makeAdder 中傳入的 x 值為 5。因此, add5(2) 的結果是 5 + 2,即 7。 總結來說,這段程式碼展示了 JavaScript 中閉包的概念。通過將 makeAdder 函式返回的匿名函式賦值給一個變數,我們可以創建具有「記住」特定值的函式。在這個例子中,我們創建了一個加法器 add5,它記住了 5 作為 x 值,並可以將其與傳入的 y 值相加。 ## 8. 請說明javascript的Promise JavaScript 的 Promise 是一個用於處理異步操作的概念和技術。它提供了一種結構化的方法來管理異步操作,以解決回調函式(callback)所帶來的問題,如回調地獄和難以處理的錯誤處理。 Promise 是一個對象,它表示一個異步操作的最終完成(或失敗)和其產生的值。以下是 Promise 的幾個關鍵概念和特性: 狀態(State): Promise 有三種狀態:待定(pending)、已完成(fulfilled)和已拒絕(rejected)。 當一個 Promise 被創建時,它的初始狀態是待定。 當異步操作成功完成時,Promise 的狀態會轉變為已完成,並將結果值傳遞給相應的處理程序。 當異步操作失敗時,Promise 的狀態會轉變為已拒絕,並將錯誤信息傳遞給相應的處理程序。 處理程序(Handlers): Promise 通過 .then()、.catch() 和 .finally() 方法來設置處理程序,以處理完成或拒絕的狀態。 .then() 方法用於處理 Promise 已完成的情況,它接受一個成功處理程序函式,並可選擇地返回一個新的 Promise。 .catch() 方法用於處理 Promise 已拒絕的情況,它接受一個錯誤處理程序函式,並可選擇地返回一個新的 Promise。 .finally() 方法用於在 Promise 完成或拒絕時執行最後的操作,它不接受參數並返回原始 Promise。 鏈式操作(Chaining): Promise 可以被鏈式調用,這使得在異步操作之間建立流程和順序變得更容易。 透過在 .then() 和 .catch() 中返回新的 Promise,可以將多個異步操作按順序連接起來,實現串行或並行處理。 錯誤處理(Error Handling): Promise 提供了統一的機制來處理異步操作中的錯誤。 在鏈式操作中,可以使用 .catch() 方法來捕獲和處理錯誤,並在需要 ## 9. 請解釋:javascipt的prototype https://developer.mozilla.org/zh-TW/docs/Learn/JavaScript/Objects/Object_prototypes 我的理解:javascript不像c#或java一樣可以去定義class,再產出實例。所以javascript用prototye當作類似物件的方法。用function底下可以呼叫function ## 10. 請解釋:javascipt的closure ## 11. 請解釋:javascipt的this

    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