JavaScript is a high-level, interpreted programming language mainly known for being web-friendly. It builds the dynamic and interactive aspects of websites, aiding in creating a responsive user interface. Questions in coding interviews revolve around the usage, strengths, and limitations of JavaScript, and its interaction with HTML and CSS. Knowledge of JavaScript’s asynchronous nature, manipulation of the Document Object Model (DOM) and understanding of events and event handling, typical design patterns, ES6+ features, and prototypal inheritance are often evaluated.
JavaScript Fundamentals
- 1.
What are the data types present in JavaScript?
Answer:JavaScript has primitive and composite data types.
Primitive Data Types
-
Boolean: Represents logical values of true or false.
-
Null: Denotes the lack of a value.
-
Undefined: Indicates a variable that has been declared but has not been assigned a value.
-
Number: Represents numeric values, including integers and floats.
-
BigInt: Allows for representation of integers with arbitrary precision.
-
String: Encapsulates sequences of characters.
-
Symbol (ES6): Provides a unique, immutable value.
Composite Data Types
- Object: Represents a set of key-value pairs and is used for more complex data structures.
- Function: A callable object that can be defined using regular function syntax or using the
new Function()constructor (rarely used).
Notable Characteristics
- JavaScript is dynamically-typed, meaning the data type of a variable can change during the execution of a program.
- Data type coercion can occur, where values are implicitly converted from one type to another in specific contexts, such as during comparisons.
- Arithmetic operations, particularly when one of the operands is a string, can lead to implicit type conversions.
-
- 2.
What is the difference between null and undefined?
Answer: - 3.
How does JavaScript handle type coercion?
Answer: - 4.
Explain the concept of hoisting in JavaScript.
Answer: - 5.
What is the scope in JavaScript?
Answer: - 6.
What is the difference between
==and===?Answer: - 7.
Describe closure in JavaScript. Can you give an example?
Answer: - 8.
What is the ‘this keyword’ and how does its context change?
Answer: - 9.
What are arrow functions and how do they differ from regular functions?
Answer: - 10.
What are template literals in JavaScript?
Answer:
JavaScript Functions and Higher-Order Functions
- 11.
What is a higher-order function in JavaScript?
Answer: - 12.
Can functions be assigned as values to variables in JavaScript?
Answer: - 13.
How do functional programming concepts apply in JavaScript?
Answer: - 14.
What are IIFEs (Immediately Invoked Function Expressions)?
Answer: - 15.
How do you create private variables in JavaScript?
Answer: