Vue.js / Nuxt.js

JavaScript Fundamentals

Variables, types, functions, arrow functions, destructuring, spread operator, template literals

20 interview questions·
Junior
1

What is the main difference between var and let in JavaScript?

Answer

The fundamental difference lies in variable scope. let has block scope, meaning a variable declared with let only exists within the block where it is defined (between curly braces). var has function scope, which can cause unexpected behaviors because the variable is accessible outside the block. This scope difference makes let the recommended choice to avoid bugs related to hoisting and scope.

2

When should const be used instead of let to declare a variable?

Answer

const should be used when a variable will never be reassigned after its initial declaration. It is good practice to declare all variables with const by default, then switch to let only if reassignment is needed. This makes the code more predictable and helps understand the developer's intent. Note: const prevents reassignment but not modification of object properties.

3

What are the primitive types in JavaScript?

Answer

JavaScript has seven primitive types: string for character strings, number for integers and decimals, boolean for true and false values, undefined for uninitialized variables, null to represent intentional absence of value, symbol to create unique identifiers, and bigint for large integers. Primitive types are immutable and compared by value, unlike objects which are compared by reference.

4

What is the difference between null and undefined in JavaScript?

5

Which operator should be used to strictly compare two values in JavaScript?

+17 interview questions

Master Vue.js / Nuxt.js for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free