# พื้นฐาน JavaScript (Vue.js / Nuxt.js) > Variables, types, functions, arrow functions, destructuring, spread operator, template literals - 20 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: Vue.js / Nuxt.js](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions.md) ## 1. ความแตกต่างหลักระหว่าง var และ let ใน JavaScript คืออะไร? **คำตอบ** ความแตกต่างพื้นฐานอยู่ที่ scope ของตัวแปร let มี block scope หมายความว่าตัวแปรที่ประกาศด้วย let จะมีอยู่เฉพาะภายในบล็อกที่มันถูกกำหนด (ระหว่างวงเล็บปีกกา) ส่วน var มี function scope ซึ่งอาจทำให้เกิดพฤติกรรมที่ไม่คาดคิดเพราะตัวแปรสามารถเข้าถึงได้นอกบล็อก ความแตกต่างของ scope นี้ทำให้ let เป็นตัวเลือกที่แนะนำเพื่อหลีกเลี่ยงบั๊กที่เกี่ยวข้องกับ hoisting และ scope ## 2. ควรใช้ const แทน let ในการประกาศตัวแปรเมื่อใด? **คำตอบ** ควรใช้ const เมื่อตัวแปรจะไม่ถูกกำหนดค่าใหม่อีกหลังจากการประกาศครั้งแรก เป็นแนวปฏิบัติที่ดีที่จะประกาศตัวแปรทั้งหมดด้วย const เป็นค่าเริ่มต้น แล้วจึงเปลี่ยนไปใช้ let เฉพาะเมื่อจำเป็นต้องกำหนดค่าใหม่ ซึ่งทำให้โค้ดคาดเดาได้ง่ายขึ้นและช่วยให้เข้าใจเจตนาของนักพัฒนา หมายเหตุ: const ป้องกันการกำหนดค่าใหม่ แต่ไม่ได้ป้องกันการแก้ไขคุณสมบัติของ object ## 3. ชนิดข้อมูล primitive ใน JavaScript มีอะไรบ้าง? **คำตอบ** JavaScript มีชนิดข้อมูล primitive เจ็ดชนิด: string สำหรับสายอักขระ, number สำหรับจำนวนเต็มและทศนิยม, boolean สำหรับค่า true และ false, undefined สำหรับตัวแปรที่ยังไม่ได้กำหนดค่า, null เพื่อแสดงการไม่มีค่าโดยตั้งใจ, symbol เพื่อสร้างตัวระบุที่ไม่ซ้ำกัน และ bigint สำหรับจำนวนเต็มขนาดใหญ่ ชนิด primitive นั้นไม่สามารถเปลี่ยนแปลงได้และเปรียบเทียบกันด้วยค่า ต่างจาก object ที่เปรียบเทียบกันด้วยการอ้างอิง ## มีอีก 17 คำถาม - ความแตกต่างระหว่าง null และ undefined ใน JavaScript คืออะไร? - ควรใช้ตัวดำเนินการใดในการเปรียบเทียบค่าสองค่าอย่างเข้มงวดใน JavaScript? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ Vue.js / Nuxt.js อื่นๆ - [JavaScript สมัยใหม่ (ES6+)](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/es6-modern-javascript.md): 20 คำถาม, Junior - [พื้นฐาน Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-basics.md): 22 คำถาม, Junior - [คอมโพเนนต์ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-components.md): 20 คำถาม, Junior - [Vue Router](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-router.md): 18 คำถาม, Junior - [Pinia State Management](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/pinia-state-management.md): 20 คำถาม, Junior - [Vuex (Legacy)](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vuex-legacy.md): 15 คำถาม, Mid-Level - [Composition API](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/composition-api.md): 24 คำถาม, Mid-Level - [ระบบ Reactivity ของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-reactivity.md): 20 คำถาม, Mid-Level - [พื้นฐาน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-fundamentals.md): 22 คำถาม, Mid-Level - [การดึงข้อมูล (Data Fetching) ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-data-fetching.md): 20 คำถาม, Mid-Level - [SSR และ SSG ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-ssr-ssg.md): 22 คำถาม, Mid-Level - [Server Routes ของ Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-server-routes.md): 20 คำถาม, Mid-Level - [โมดูล Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-modules.md): 18 คำถาม, Mid-Level - [Composables ใน Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-composables.md): 20 คำถาม, Mid-Level - [ฟอร์มและการตรวจสอบ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-forms-validation.md): 20 คำถาม, Mid-Level - [การจัดการสถานะใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-state-management.md): 18 คำถาม, Mid-Level - [การทดสอบ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-testing.md): 20 คำถาม, Mid-Level - [การ Deploy Nuxt และ CI/CD](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-deployment-cicd.md): 22 คำถาม, Mid-Level - [ประสิทธิภาพของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-performance.md): 22 คำถาม, Senior - [รูปแบบขั้นสูงของ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-advanced-patterns.md): 24 คำถาม, Senior - [TypeScript กับ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/typescript-vue.md): 22 คำถาม, Senior - [การยืนยันตัวตน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-auth.md): 20 คำถาม, Senior - [SEO ด้วย Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-seo.md): 20 คำถาม, Senior - [การทำ Internationalization ใน Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-i18n.md): 18 คำถาม, Senior - [สถาปัตยกรรม Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-architecture.md): 22 คำถาม, Senior - [ความปลอดภัยของ Nuxt](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/nuxt-security.md): 20 คำถาม, Senior - [ระบบนิเวศ Vue](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/vue-ecosystem.md): 18 คำถาม, Senior - [การย้าย Vue 2→3 & Nuxt 2→3](https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/migration-vue2-vue3-nuxt2-nuxt3.md): 22 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/vue-nuxt/interview-questions/javascript-fundamentals