Episode 1 — Fundamentals / 1.13 — Introduction to JavaScript

1.13 — Exercise Questions: Introduction to JavaScript

Practice questions for all eight subtopics in Section 1.13. Short-answer, prediction, and tiny coding tasks. Try each without reopening the lesson files first.

How to use this material (instructions)

  1. Read lessons in orderREADME.md, then 1.13.a1.13.h.
  2. Answer closed-book first — write bullets or a few lines, then compare to the lesson.
  3. Type code in DevTools — use the Console for one-liners; use an HTML file + external app.js for scripts.
  4. Interview prep — pair with 1.13-Interview-Questions.md.
  5. Quick review1.13-Quick-Revision.md.

1.13.a — What is JavaScript? (Q1–Q6)

Q1. In one sentence each, describe the roles of HTML, CSS, and JavaScript on a web page.

Q2. Name three environments or contexts where JavaScript is commonly used today.

Q3. True or false: JavaScript and Java are the same language with different names. Explain.

Q4. What does it mean that JavaScript is interpreted (high level) in the browser context?

Q5. Give one example of something JavaScript can do that CSS alone cannot.

Q6. What is ECMAScript, and how does it relate to “JavaScript”?


1.13.b — Where JS runs (Q7–Q12)

Q7. List three browser globals or APIs that do not exist in plain Node.js.

Q8. List two things Node.js is commonly used for that browser scripts typically are not.

Q9. Why does document.querySelector("body") not work in a default Node REPL?

Q10. What engine powers Node.js and also Chrome?

Q11. Can you use fetch in modern Node? (Answer conceptually — availability depends on version; explain the idea.)

Q12. Hands-on: Open Node (if installed) and run console.log(typeof globalThis). In a browser console, run the same. What do you observe?


1.13.c — <script> tag (Q13–Q20)

Q13. Write the HTML for an external script main.js that should run after HTML is parsed, without blocking parsing during download.

Q14. What is the difference between defer and async for <script src="...">?

Q15. Why were scripts traditionally placed just before </body>?

Q16. What does type="module" imply about import / export and default deferral?

Q17. What is a downside of large inline <script> blocks in HTML?

Q18. If script A must run before script B, and both use async, is order guaranteed? Why?

Q19. What problem does defer solve compared to a blocking script in <head>?

Q20. Hands-on: Create index.html + app.js with console.log("loaded"). Try with and without defer and observe in Network + Console.


1.13.d — Console (Q21–Q28)

Q21. Name four methods on console besides log.

Q22. What is a stack trace, and when do you see it in the Console?

Q23. What is a REPL, and how does the browser Console act like one?

Q24. What is a ReferenceError? Give a tiny example that causes one.

Q25. Why should you usually fix the first error before chasing later ones?

Q26. What does console.table([{a:1},{a:2}]) help you visualize?

Q27. Hands-on: Log an object { name: "Test", score: 10 } and expand it in DevTools — what do nested properties show?

Q28. What is the difference between console.warn and console.error from a practical debugging perspective (not just color)?


1.13.e — var, let, const (Q29–Q38)

Q29. When should you use const vs let?

Q30. What happens if you reassign a const binding?

Q31. Can you mutate an object held in a const variable? Show a one-line example.

Q32. What is block scope? Give an example where let is visible inside if but not outside.

Q33. Why is var discouraged in new code?

Q34. What is the temporal dead zone for let / const?

Q35. Does top-level let x = 1 in a browser script create window.x? What about var x = 1?

Q36. Predict the output:

console.log(a);
var a = 2;

Q37. Would the same snippet with let instead of var behave the same? Why?

Q38. Hands-on: Declare const pi = 3.14 and try pi = 3 — what error appears?


1.13.f — Naming & clean code (Q39–Q44)

Q39. Convert user name into a valid camelCase identifier.

Q40. When is PascalCase appropriate in JavaScript?

Q41. Why is const data = ... often worse than const userProfile = ...?

Q42. Name two good prefixes for boolean variable names.

Q43. Should you comment i++? Why or why not?

Q44. Give an example of a SCREAMING_SNAKE_CASE constant you might define in a small app.


1.13.g — Data types (Q45–Q54)

Q45. List the seven primitive types in JavaScript (ES6+).

Q46. What is the difference between null and undefined in typical usage?

Q47. What does typeof null return? Is that accurate?

Q48. How do you reliably check if a value is null?

Q49. How do you check if a value is an array?

Q50. Are strings mutable or immutable? What does "a".toUpperCase() return?

Q51. If const a = { x: 1 }; const b = a; what is b.x after b.x = 2?

Q52. What is the result of typeof NaN?

Q53. Why should beginners prefer === over ==?

Q54. Hands-on: Run typeof [] and Array.isArray([]) in the Console — compare results.


1.13.h — Mini programs (Q55–Q62)

Q55. Why must you wrap prompt("Age") with Number() before adding 1 for a numeric “next birthday”?

Q56. What does prompt return if the user clicks Cancel?

Q57. Write a three-line script that asks for a name and **alert**s a greeting.

Q58. Extend the calculator idea: how would you detect invalid input after Number(prompt(...))?

Q59. What does confirm return?

Q60. Why are alert / prompt poor choices for production UX?

Q61. Exercise: Write a program that asks for celsius and prints fahrenheit using F = C * 9/5 + 32 (use console.log).

Q62. Reflection: Which subtopic (1.13.a1.13.h) was hardest? Name two concrete follow-up actions.


Answer hints

QHint
Q2Browser, Node, embedded runtimes (e.g. Electron), serverless workers — any three valid
Q14defer preserves order after parse; async runs ASAP, order not guaranteed between async scripts
Q16ES modules; implicit strict; deferred execution
Q29const default; let when reassignment needed
Q34Cannot access let/const before declaration line in its scope
Q36undefined then assignment — var hoisted, init not hoisted
Q37let throws ReferenceError (TDZ)
Q47"object" — quirk; use value === null
Q49Array.isArray(x)
Q55prompt returns string; "5" + 1 is string concat without conversion
Q56null

← Back to 1.13 — Introduction to JavaScript (README)