JavaScript Fundamentals Flashcards
Variables & Data Types Operators & Expressions Functions & Scope Hoisting & Closures (91 cards)
What are variables in JavaScript?
Variables are containers for storing data values. They can be declared using var, let, or const.
What are the data types in JavaScript?
JavaScript has primitive types (Number, String, Boolean, null, undefined, Symbol, BigInt) and non-primitive types (Object, Array, Function).
What are the advantages of using ‘let’ and ‘const’ over ‘var’?
‘let’ and ‘const’ provide block scope, reducing errors due to variable hoisting and scope leakage associated with ‘var’.
What are the disadvantages of using ‘var’?
‘var’ is function-scoped and can lead to unexpected behavior due to hoisting and lack of block scope.
What is a best practice for declaring variables in JavaScript?
Use ‘const’ by default, and ‘let’ when reassignment is needed. Avoid using ‘var’ to prevent scope-related issues.
What is a use case for using ‘const’ in JavaScript?
Declaring constants or variables that should not be reassigned, such as configuration values.
How do variables impact system design in JavaScript?
Proper variable declaration and scoping lead to more predictable and maintainable code, reducing bugs and side effects.
What is an example of variable hoisting in JavaScript?
Accessing a ‘var’ declared variable before its declaration results in ‘undefined’ due to hoisting.
What are the architectural implications of improper variable scoping?
Can lead to tightly coupled code and unintended side effects, making maintenance and scaling difficult.
What is a performance consideration with variable declarations?
Using ‘let’ and ‘const’ can help prevent memory leaks by limiting the scope and lifespan of variables.
How can you monitor or debug variable-related issues?
Use debugging tools and linters to track variable declarations, scopes, and potential leaks.
What is a real-world tradeoff when choosing variable declarations?
Choosing between ‘let’ and ‘const’ for flexibility versus immutability and safety.
What is a common interview question about JavaScript variables?
Explain the difference between ‘var’, ‘let’, and ‘const’.
What is a potential gotcha with variable declarations?
Using ‘var’ can lead to unexpected behavior due to its function-scoped nature and hoisting.
What are operators in JavaScript?
Operators are symbols that perform operations on operands, such as addition (+), subtraction (-), and assignment (=).
What are expressions in JavaScript?
Expressions are combinations of values and operators that compute to a value.
What are the advantages of using strict equality (===) over loose equality (==)?
Strict equality checks for both value and type, reducing unexpected type coercion.
What are the disadvantages of using loose equality (==)?
Can lead to unexpected results due to type coercion.
What is a best practice when using operators in JavaScript?
Prefer strict equality (===) and avoid using ‘==’ to prevent type coercion issues.
What is a use case for using the ternary operator?
Simplifying conditional assignments: let result = condition ? value1 : value2;
How do operators impact system design in JavaScript?
Proper use of operators ensures accurate computations and logic flow, leading to reliable applications.
What is an example of using logical operators in JavaScript?
Using ‘&&’ to execute code only if multiple conditions are true.
What are the architectural implications of operator misuse?
Incorrect operator usage can lead to logic errors, affecting application behavior and reliability.
What is a performance consideration with complex expressions?
Overly complex expressions can be harder to read and maintain, potentially leading to performance issues.