JS basics Flashcards
(38 cards)
Q: What is JavaScript?
A: A core web technology enabling interactivity in browsers; also used in Node.js, Electron, React Native.
Q: Who created JavaScript and when?
A: Brendan Eich in 1995; originally named Mocha, then LiveScript, and finally JavaScript.
Q: What is ECMAScript?
A: The standardized version of JavaScript maintained by ECMA. Major versions include ES1, ES5, ES6.
Q: How can JavaScript be run?
A: Via <.script> in HTML, browser console, Node.js, or REPL environments.
Q: What are the keywords to declare variables in JavaScript?
A: var, let, and const.
Q: Differences between var, let, and const?
A: var is function-scoped; let/const are block-scoped. const can’t be reassigned.
Q: Can const variables be mutated?
A: Yes, for objects/arrays – only reassignment is disallowed.
Q: What happens when using var inside a loop?
A: It leaks outside the block due to function scope.
Q: What is hoisting in JavaScript?
A: JavaScript lifts declarations (not initializations) to the top of their scope.
Q: What gets hoisted?
A: var declarations and function declarations; let/const hoisted but uninitialized (TDZ).
Q: What is the temporal dead zone (TDZ)?
A: The phase between scope entry and variable declaration where access throws an error.
Q: What are best practices for naming variables?
A: Use camelCase, meaningful names, constants in UPPER_SNAKE_CASE, avoid reserved words.
Q: Should variable names reflect type or purpose?
A: Purpose – e.g., userList over arrUsers.
Q: What are the types of scopes in JavaScript?
A: Global, Function, Block, Module.
Q: Difference between block and function scope?
A: Block scope is within {}; function scope applies to function body.
Q: What is lexical scope?
A: Scope defined by code structure – inner functions can access outer variables.
Q: What are the 7 primitive data types in JavaScript?
A: Number, String, Boolean, Null, Undefined, Symbol, BigInt.
Q: What is typeof null?
A: ‘object’ – due to a long-standing JavaScript bug.
Q: Is typeof [] equal to ‘array’?
A: No – use Array.isArray() or Object.prototype.toString.call([]).
Q: Example of different number notations?
A: 255 == 0xff == 0b11111111 == 0.255e3; all evaluate to same number.
Q: Difference between type casting and type coercion?
A: Casting is explicit (e.g., Number(‘5’)); coercion is implicit (e.g., ‘5’ - 1).
Q: What is implicit coercion?
A: JavaScript automatically converts data types during operations (e.g., ‘5’ + 1 = ‘51’).
Q: What is explicit type casting?
A: Manual conversion using String(), Number(), Boolean().
Q: When does coercion happen implicitly?
A: During arithmetic, comparisons, string ops, template literals.