JavaScript Interview Questions and Answers
Q: What is JavaScript and how is it different from Java?
A: JavaScript is a high-level, interpreted programming language mainly used for creating interactive
web pages. It can run in web browsers and on servers using platforms like Node.js.
Differences between JavaScript and Java:
- JavaScript is an interpreted scripting language; Java is a compiled programming language.
- JavaScript is dynamically typed; Java is statically typed.
- JavaScript uses prototype-based inheritance; Java uses class-based inheritance.
- JavaScript is mainly used for web development; Java is used in enterprise applications, Android
development, etc.
Q: What is meant by high-level, interpreted, and scripting language?
A: - High-level: Easy to read and write, closer to human language.
- Interpreted: Code is executed line by line by an interpreter, without needing compilation.
- Scripting: Automates tasks or controls other software; commonly used in web development.
Q: Explain the different data types in JavaScript.
A: JavaScript has 8 main data types:
Primitive Types:
- String: Text (e.g., "Hello")
- Number: Numeric values (e.g., 42, 3.14)
- BigInt: Large integers (e.g., 123n)
- Boolean: true or false
- Undefined: A variable declared but not assigned a value
- Null: An intentionally empty value
- Symbol: Unique and immutable identifier
Non-Primitive Type:
- Object: A collection of properties (e.g., { name: "John" })
- Includes arrays, functions, and more
You can check a variable's type using `typeof`.