Title: Javascript Fundamentals — LearnCoachAssist

Q: What is JavaScript?
A: JavaScript is a high-level, interpreted programming language primarily used for web development to make web pages interactive. It is the scripting language of the Web, supported by all modern browsers, and follows the ECMAScript specification.

Q: Who created JavaScript and in what year?
A: JavaScript was created by Brendan Eich in 1995 while working at Netscape. It was initially called Mocha, then LiveScript, before being renamed JavaScript.

Q: What is ECMAScript?
A: ECMAScript (ES) is the standardized scripting language specification upon which JavaScript is based. The latest stable version is ES2023, with JavaScript implementing all ES features plus browser-specific ones.

Q: How do you include JavaScript in an HTML file?
A: Use the <script> tag in the HTML, either inline with code between tags or externally via <script src="script.js"></script>. Place it before the closing </body> tag for better performance.

Q: What does console.log() do?
A: console.log() outputs a message to the browser's console for debugging and logging. It can log multiple arguments of any type, like console.log('Hello', 42);.

Q: What are the ways to declare variables in JavaScript?
A: Variables can be declared using var (function-scoped), let (block-scoped), or const (block-scoped constant). let and const were introduced in ES6.

Q: What are JavaScript's primitive data types?
A: The primitive types are string, number, bigint, boolean, undefined, null, and symbol. They are immutable basic values.

Q: How do you check the type of a value?
A: Use the typeof operator, e.g., typeof 'hello' returns 'string'. It returns a string describing the type.

Q: What is the difference between null and undefined?
A: null represents an intentional absence of value, while undefined means a variable has been declared but not assigned. typeof null is 'object', a historical bug.

Q: What is type coercion in JavaScript?
A: Type coercion is JavaScript's automatic conversion of values between types, like '5' + 1 becoming '51'. Use === for strict equality to avoid it.

Q: What are arithmetic operators?
A: Arithmetic operators include + (addition), - (subtraction), * (multiplication), / (division), % (modulus), ** (exponentiation). They work on numbers.

Q: What do comparison operators return?
A: Comparison operators like ==, ===, !=, !==, >, etc., return a boolean (true or false). === checks value and type.

Q: What are logical operators?
A: Logical operators are && (AND), || (OR), and ! (NOT). They perform boolean logic and enable short-circuit evaluation.

Q: How does the if-else statement work?
A: The if statement executes code if a condition is truthy; else if checks alternatives; else runs if all fail. Conditions coerce to boolean.

Q: What is a switch statement used for?
A: A switch statement evaluates an expression and executes code matching a case value, using break to exit. It supports default for no match.

Q: Describe the for loop syntax.
A: A for loop has for (init; condition; increment) { ... }, e.g., for (let i=0; i<5; i++). Init runs once, condition checks each iteration.

Q: What is the difference between while and do-while loops?
A: while checks condition before executing; do-while executes once then checks. do-while guarantees at least one iteration.

Q: How do you declare a function?
A: Use function name(parameters) { ... } for declarations, hoisted at runtime. Expressions like const func = function() {} are not hoisted.

Q: What are function parameters and arguments?
A: Parameters are variables in the function definition; arguments are values passed when calling. Functions can access arguments object for all passed values.

Q: What does the return statement do?
A: The return statement exits the function and sends a value back to the caller. Without it, functions return undefined.

Q: How do you create an array?
A: Arrays are created with [], e.g., const arr = [1, 'a', true]; or new Array(). They are zero-indexed.

Q: What methods add/remove from arrays?
A: push() adds to end, pop() removes from end, shift() from start, unshift() adds to start. They mutate the array.

Q: How do you access object properties?
A: Use dot notation obj.prop or bracket obj['prop']. Bracket allows dynamic keys like variables.

Q: What is an object literal?
A: An object literal is { key: value }, e.g., const obj = {name: 'JS'};. Keys are strings or symbols, values any type.

Q: What is JavaScript scope?
A: Scope determines variable accessibility. Global scope is outermost; function scope (var) or block scope (let/const) limits to their block.

Q: What is hoisting?
A: Hoisting moves variable and function declarations to the top of their scope before execution. var is hoisted with undefined; let/const have Temporal Dead Zone.

Q: What is 'use strict'?
A: 'use strict'; enables strict mode, enforcing better practices like no undeclared variables or duplicate parameters. It's a string literal at script/function top.

Q: What does the 'this' keyword refer to?
A: 'this' refers to the execution context object. In global scope it's window (browser); in methods it's the object; arrow functions inherit from parent.

Q: What is a closure?
A: A closure is a function that retains access to its outer scope's variables even after the outer function finishes. Useful for data privacy and modules.

Q: What is an IIFE?
A: Immediately Invoked Function Expression (IIFE) is (function() { ... })();. It runs instantly, creating private scope to avoid globals.

Q: What are template literals?
A: Template literals use backticks `Hello ${name}` for strings with embedded expressions. They support multi-line strings and tagged templates.

Q: What is destructuring assignment?
A: Destructuring extracts values from arrays/objects into variables, e.g., const [a, b] = [1, 2]; or const {x} = {x: 10};. ES6 feature.

Q: What is the spread operator?
A: Spread ... expands iterables, e.g., const newArr = [...oldArr, 1]; for shallow copy or Math.max(...nums) for function args.

Q: What are rest parameters?
A: Rest ...args collects remaining arguments into an array, e.g., function sum(...nums) {}. Only last parameter.

Q: What are default parameters?
A: Default parameters set fallback values, e.g., function greet(name = 'World') {}. Evaluated if undefined.

Q: How do you define a class in ES6?
A: Use class MyClass { constructor(props) { this.props = props; } method() {} }. Syntactic sugar over prototypes.

Q: What is class inheritance?
A: Use extends and super(), e.g., class Child extends Parent { constructor() { super(); } }. Calls parent constructor.

Q: What is JSON?
A: JSON (JavaScript Object Notation) is a text format for data interchange, like {"name": "JS"}. Use JSON.parse() to object, JSON.stringify() to string.

Q: How do you work with the Date object?
A: Create with new Date() for current time or new Date('2023-01-01'). Methods: getFullYear(), setHours(), etc.

Q: What is the Math object?
A: Math is a built-in object with no constructor, providing Math.random(), Math.floor(), Math.PI, etc., for math operations.

Q: What does Array.prototype.map() do?
A: map() creates a new array with results of calling a function on each element, e.g., [1,2].map(x => x*2) returns [2,4]. Doesn't mutate original.

Q: What is Array.prototype.filter()?
A: filter() creates a new array with elements passing a test, e.g., [1,2,3].filter(x => x>1) returns [2,3]. Returns boolean from callback.

Q: What is Array.prototype.reduce()?
A: reduce() applies a function against accumulator and each element, reducing to single value, e.g., sum: [1,2].reduce((a,b)=>a+b, 0).

Q: How do you select a DOM element?
A: Use document.getElementById('id'), document.querySelector('.class'), or document.querySelectorAll(). Returns Element or NodeList.

Q: What is an event listener?
A: Event listeners respond to DOM events like clicks: element.addEventListener('click', handler). Can remove with removeEventListener().

Q: What is the event object?
A: The event object (e) passed to handlers contains event details like e.target, e.preventDefault() to stop default behavior.

Q: What are Promises?
A: Promises represent eventual completion/failure of async operations, with .then(), .catch(). States: pending, fulfilled, rejected.

Q: How does async/await work?
A: async functions return Promises; await pauses until Promise settles, e.g., const data = await fetch(url);. Use try/catch for errors.

Q: What is the call stack?
A: The call stack tracks function execution order, LIFO. Browsers use it with event loop for async tasks like setTimeout.

Q: What is the difference between == and ===?
A: == coerces types before comparing; === checks value and type strictly. Prefer === to avoid bugs.

Q: What is optional chaining in JavaScript?
A: Optional chaining (?.) safely reads nested properties or calls methods without throwing when an intermediate value is null or undefined.

Q: What does the nullish coalescing operator do?
A: ?? returns the fallback only when the left side is null or undefined, unlike || which also treats 0, '', and false as fallback cases.

Q: What is a JavaScript module?
A: A module is a file that can export and import values using export and import, helping organize code and avoid global namespace pollution.

Q: What is a pure function?
A: A pure function always returns the same output for the same input and does not create side effects such as changing external state or making network calls.

Q: What is debouncing?
A: Debouncing delays a function call until a quiet period has passed, commonly used for search inputs so an API call is not made on every keystroke.

Q: What is throttling?
A: Throttling ensures a function runs at most once in a defined interval, useful for scroll, resize, and mouse-move handlers.

Q: What is the rest parameter?
A: A rest parameter (...args) collects multiple function arguments into a single array-like variable.

Q: What does lexical scope mean in JavaScript fundamentals?
A: Lexical scope means a function can access variables based on where it was written in the source code.

Q: Why does lexical scope matter in JavaScript fundamentals?
A: It explains closures, module patterns, and why functions can remember outer variables.

Q: What is a common mistake with lexical scope?
A: Assuming scope depends on where a function is called instead of where it is defined.

Q: How can you practice lexical scope?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using lexical scope?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of lexical scope?
A: A simple example is using lexical scope in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does event delegation mean in JavaScript fundamentals?
A: Event delegation attaches one listener to a parent and handles events from child elements through bubbling.

Q: Why does event delegation matter in JavaScript fundamentals?
A: It improves performance and works well for dynamically added elements.

Q: What is a common mistake with event delegation?
A: Adding separate listeners to hundreds of child nodes when one parent listener would work.

Q: How can you practice event delegation?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using event delegation?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of event delegation?
A: A simple example is using event delegation in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does Promise chaining mean in JavaScript fundamentals?
A: Promise chaining sequences asynchronous steps by returning values or promises from .then() callbacks.

Q: Why does Promise chaining matter in JavaScript fundamentals?
A: It keeps async workflows predictable and prevents deeply nested callbacks.

Q: What is a common mistake with Promise chaining?
A: Forgetting to return a promise, causing the next step to run too early.

Q: How can you practice Promise chaining?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using Promise chaining?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of Promise chaining?
A: A simple example is using promise chaining in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does async error handling mean in JavaScript fundamentals?
A: Async error handling uses try/catch around await or .catch() on promises.

Q: Why does async error handling matter in JavaScript fundamentals?
A: It prevents failed requests or rejected promises from silently breaking user flows.

Q: What is a common mistake with async error handling?
A: Wrapping only synchronous code and missing rejected promises.

Q: How can you practice async error handling?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using async error handling?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of async error handling?
A: A simple example is using async error handling in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does immutability mean in JavaScript fundamentals?
A: Immutability means creating new values instead of changing existing ones.

Q: Why does immutability matter in JavaScript fundamentals?
A: It makes state changes easier to reason about in UI frameworks and reducers.

Q: What is a common mistake with immutability?
A: Mutating arrays or objects directly and expecting change detection to work.

Q: How can you practice immutability?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using immutability?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of immutability?
A: A simple example is using immutability in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does prototype chain mean in JavaScript fundamentals?
A: The prototype chain is how JavaScript looks up properties on an object and then on its prototypes.

Q: Why does prototype chain matter in JavaScript fundamentals?
A: It explains inheritance, methods, and why objects can share behavior.

Q: What is a common mistake with prototype chain?
A: Confusing prototypes with classical classes in languages like Java or C#.

Q: How can you practice prototype chain?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using prototype chain?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of prototype chain?
A: A simple example is using prototype chain in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does strict mode mean in JavaScript fundamentals?
A: Strict mode enables stricter parsing and error handling with 'use strict'.

Q: Why does strict mode matter in JavaScript fundamentals?
A: It catches mistakes such as accidental globals and unsafe assignments.

Q: What is a common mistake with strict mode?
A: Assuming all old JavaScript behavior remains valid under strict mode.

Q: How can you practice strict mode?
A: Apply it to a small realistic example, explain the decision out loud, then check whether the result matches the intended outcome.

Q: What question should you ask when using strict mode?
A: Ask: what problem is this solving, what trade-off does it create, and how will I know it worked?

Q: What is a simple example of strict mode?
A: A simple example is using strict mode in a small project, note, or decision before applying it to a larger real-world situation.

Q: What does microtasks mean in JavaScript fundamentals?
A: Microtasks are high-priority async callbacks such as promise callbacks that run after the current stack before many macrotasks.