JS basics Flashcards

(38 cards)

1
Q

Q: What is JavaScript?

A

A: A core web technology enabling interactivity in browsers; also used in Node.js, Electron, React Native.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Who created JavaScript and when?

A

A: Brendan Eich in 1995; originally named Mocha, then LiveScript, and finally JavaScript.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: What is ECMAScript?

A

A: The standardized version of JavaScript maintained by ECMA. Major versions include ES1, ES5, ES6.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: How can JavaScript be run?

A

A: Via <.script> in HTML, browser console, Node.js, or REPL environments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: What are the keywords to declare variables in JavaScript?

A

A: var, let, and const.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: Differences between var, let, and const?

A

A: var is function-scoped; let/const are block-scoped. const can’t be reassigned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Can const variables be mutated?

A

A: Yes, for objects/arrays – only reassignment is disallowed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What happens when using var inside a loop?

A

A: It leaks outside the block due to function scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: What is hoisting in JavaScript?

A

A: JavaScript lifts declarations (not initializations) to the top of their scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What gets hoisted?

A

A: var declarations and function declarations; let/const hoisted but uninitialized (TDZ).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q: What is the temporal dead zone (TDZ)?

A

A: The phase between scope entry and variable declaration where access throws an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q: What are best practices for naming variables?

A

A: Use camelCase, meaningful names, constants in UPPER_SNAKE_CASE, avoid reserved words.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q: Should variable names reflect type or purpose?

A

A: Purpose – e.g., userList over arrUsers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q: What are the types of scopes in JavaScript?

A

A: Global, Function, Block, Module.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q: Difference between block and function scope?

A

A: Block scope is within {}; function scope applies to function body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q: What is lexical scope?

A

A: Scope defined by code structure – inner functions can access outer variables.

17
Q

Q: What are the 7 primitive data types in JavaScript?

A

A: Number, String, Boolean, Null, Undefined, Symbol, BigInt.

18
Q

Q: What is typeof null?

A

A: ‘object’ – due to a long-standing JavaScript bug.

19
Q

Q: Is typeof [] equal to ‘array’?

A

A: No – use Array.isArray() or Object.prototype.toString.call([]).

20
Q

Q: Example of different number notations?

A

A: 255 == 0xff == 0b11111111 == 0.255e3; all evaluate to same number.

21
Q

Q: Difference between type casting and type coercion?

A

A: Casting is explicit (e.g., Number(‘5’)); coercion is implicit (e.g., ‘5’ - 1).

22
Q

Q: What is implicit coercion?

A

A: JavaScript automatically converts data types during operations (e.g., ‘5’ + 1 = ‘51’).

23
Q

Q: What is explicit type casting?

A

A: Manual conversion using String(), Number(), Boolean().

24
Q

Q: When does coercion happen implicitly?

A

A: During arithmetic, comparisons, string ops, template literals.

25
Q: Difference between == and ===?
A: == allows coercion; === checks type and value strictly.
26
Q: What happens during object-to-primitive coercion?
A: JavaScript calls valueOf(), then toString().
27
Q: What are built-in objects in JS?
A: Global language-provided objects: Number, String, Object, Math, Date, Error, etc.
28
Q: Difference between new Number(5) and Number(5)?
A: new Number(5) creates object; Number(5) returns primitive number.
29
Q: Can Math be instantiated?
A: No – it's a utility object with static methods.
30
Q: What does the Error object do?
A: Handles exceptions with properties like name, message, and stack.
31
Q: What is typeof in JavaScript?
A: An operator that returns a string indicating the operand's data type.
32
Q: What does typeof function() {} return?
A: 'function' – a special case.
33
Q: How to differentiate arrays and objects?
A: Use Array.isArray() or Object.prototype.toString.call(val).
34
Q: What is a prototype in JavaScript?
A: An object from which other objects inherit properties and methods.
35
Q: How to access or set a prototype?
A: Use Object.getPrototypeOf(obj), Object.setPrototypeOf(obj), or Object.create(proto).
36
Q: What is prototypal inheritance?
A: Objects inherit from other objects via the prototype chain.
37
Q: Difference from classical inheritance?
A: Classical uses classes; prototypal uses direct object-to-object delegation.
38