# พื้นฐาน JavaScript (React / Next.js) > ตัวแปร (let/const/var), ชนิดข้อมูล, closures, this, arrow functions, destructuring, spread/rest - 25 คำถามสัมภาษณ์ - Junior - [คำถามสัมภาษณ์: React / Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions.md) ## 1. ความแตกต่างหลักระหว่าง let กับ var คืออะไร? **คำตอบ** let ประกาศตัวแปรที่มีขอบเขตระดับบล็อก หมายความว่าตัวแปรจะมีอยู่เฉพาะภายในบล็อกที่ถูกกำหนด (ระหว่างวงเล็บปีกกา) var มีขอบเขตระดับฟังก์ชัน ซึ่งอาจทำให้เกิดบั๊กที่ไม่คาดคิดเพราะตัวแปรสามารถเข้าถึงได้ตลอดทั้งฟังก์ชัน การใช้ let เป็นค่าเริ่มต้นจะช่วยป้องกันปัญหา hoisting และการรั่วไหลของตัวแปรในลูปหรือเงื่อนไข ## 2. ควรใช้การประกาศแบบใดสำหรับค่าที่ไม่เปลี่ยนแปลง? **คำตอบ** const ช่วยให้ประกาศค่าคงที่ที่ไม่สามารถกำหนดค่าอ้างอิงใหม่ได้ สิ่งนี้ช่วยเพิ่มความสามารถในการอ่านโค้ดโดยบ่งบอกเจตนาอย่างชัดเจนและป้องกันการแก้ไขโดยไม่ตั้งใจ โปรดทราบว่าสำหรับอ็อบเจกต์และอาร์เรย์ const จะป้องกันเฉพาะการกำหนดค่าอ้างอิงใหม่เท่านั้น ไม่ได้ป้องกันการแก้ไขเนื้อหา นี่คือแนวปฏิบัติที่ดีที่สุดสำหรับการประกาศค่าที่ไม่เปลี่ยนแปลง ## 3. ชนิดข้อมูลใดของ JavaScript ที่ไม่ใช่ primitive? **คำตอบ** Object เป็นชนิดข้อมูลเดียวที่ไม่ใช่ primitive ใน JavaScript ชนิด primitive ได้แก่ string, number, boolean, null, undefined, symbol และ bigint Object จะถูกจัดเก็บโดยอ้างอิงในหน่วยความจำ ในขณะที่ primitive จะถูกจัดเก็บโดยค่า ซึ่งหมายความว่าการแก้ไข object จะส่งผลต่อการอ้างอิงทั้งหมดที่ชี้ไปยัง object นั้น แต่การคัดลอก primitive จะสร้างค่าใหม่ที่เป็นอิสระ ## มีอีก 22 คำถาม - typeof null ใน JavaScript คืนค่าอะไร? - ความแตกต่างระหว่าง == กับ === คืออะไร? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ React / Next.js อื่นๆ - [พื้นฐาน React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-fundamentals.md): 20 คำถาม, Junior - [React Hooks](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-hooks.md): 22 คำถาม, Junior - [วงจรชีวิตของ component](https://sharpskill.dev/th/technologies/react-next/interview-questions/component-lifecycle.md): 18 คำถาม, Junior - [React Router](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-router.md): 20 คำถาม, Junior - [การจัดการ state ด้วย Context](https://sharpskill.dev/th/technologies/react-next/interview-questions/state-management-context.md): 18 คำถาม, Junior - [ฟอร์มและ Controlled Components](https://sharpskill.dev/th/technologies/react-next/interview-questions/forms-controlled-components.md): 20 คำถาม, Mid-Level - [การดึงข้อมูลและ API](https://sharpskill.dev/th/technologies/react-next/interview-questions/fetching-data-api.md): 20 คำถาม, Mid-Level - [React Query (TanStack Query)](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-query-tanstack.md): 20 คำถาม, Mid-Level - [Styling & CSS-in-JS](https://sharpskill.dev/th/technologies/react-next/interview-questions/styling-css-in-js.md): 18 คำถาม, Mid-Level - [พื้นฐาน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-fundamentals.md): 25 คำถาม, Mid-Level - [TypeScript กับ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/typescript-react.md): 20 คำถาม, Mid-Level - [การดึงข้อมูล Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-data-fetching.md): 24 คำถาม, Mid-Level - [Server Actions ของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-server-actions.md): 20 คำถาม, Mid-Level - [การกำหนดเส้นทางและการนำทางใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-routing-navigation.md): 22 คำถาม, Mid-Level - [API Routes ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-api-routes.md): 20 คำถาม, Mid-Level - [Metadata & SEO ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-metadata-seo.md): 18 คำถาม, Mid-Level - [Middleware และ Auth ใน Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-middleware-auth.md): 22 คำถาม, Mid-Level - [การทดสอบ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-testing.md): 20 คำถาม, Mid-Level - [Zustand State Management](https://sharpskill.dev/th/technologies/react-next/interview-questions/zustand-state-management.md): 18 คำถาม, Mid-Level - [การเพิ่มประสิทธิภาพ React](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-performance-optimization.md): 22 คำถาม, Senior - [Error Boundaries & การจัดการข้อผิดพลาด](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-error-boundaries.md): 18 คำถาม, Senior - [Advanced React Patterns](https://sharpskill.dev/th/technologies/react-next/interview-questions/advanced-react-patterns.md): 20 คำถาม, Senior - [ฟีเจอร์ขั้นสูงของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-advanced-features.md): 24 คำถาม, Senior - [การ Deploy & Production ของ Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-deployment-production.md): 20 คำถาม, Senior - [Architecture & Design Patterns](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-architecture-patterns.md): 22 คำถาม, Senior - [React Server Components](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-server-components.md): 26 คำถาม, Senior - [การแปลภาษา Next.js](https://sharpskill.dev/th/technologies/react-next/interview-questions/nextjs-internationalization.md): 20 คำถาม, Senior - [React ความปลอดภัย & แนวปฏิบัติที่ดีที่สุด](https://sharpskill.dev/th/technologies/react-next/interview-questions/react-security-best-practices.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/react-next/interview-questions/javascript-essentials