TypeScript vs JavaScript: Key Differences with Examples
TypeScript checks types at compile time and outputs plain JavaScript; JavaScript checks them only at runtime. A side-by-side comparison with real compiler errors.
TypeScript checks types at compile time and outputs plain JavaScript; JavaScript checks them only at runtime. A side-by-side comparison with real compiler errors.
Get the current date in TypeScript, create dates, add days and months, compare and format them, and avoid the time zone and JSON pitfalls of the Date object.
Find elements in a TypeScript array with find(), findIndex(), findLast() and findLastIndex(), handle the T | undefined result, and pick the right search method.
Number.isFinite() is the reliable way to check if a variable is a number in JavaScript. Learn why typeof and the global isNaN() let bad values through, how to validate numeric strings from forms, and how to write a TypeScript type guard.
Filter an array of objects by property in TypeScript with filter(): single and multiple conditions, lists of values, nested and optional fields, a typed filterBy() helper and type narrowing.
A callback function in TypeScript is a function passed to another function and called later. Examples cover callback types, passing parameters, error-first callbacks, Promises and async/await.
undefined means a value was never set, null means it was set to “nothing” on purpose. Learn where each comes from, how they differ, and how strictNullChecks, ?? and ?. handle them.
The difference between == and === in TypeScript with real results, the type conversion rules of ==, the compiler checks, and the one accepted use of == null.
Hoisting makes every declaration exist from the start of its scope. var reads as undefined, let, const and class throw in the temporal dead zone, and function declarations work anywhere.
JavaScript has eight falsy values; everything else, including “0”, [] and {}, is truthy. Learn where the conversion happens, how TypeScript narrows with it, and the bugs it causes.
Mask passwords, card numbers, emails and tokens before they reach a log file, using a JSON.stringify() replacer, a structuredClone() copy, regex for free text, toJSON(), and pino’s redact option.
Learn Jasmine unit testing with TypeScript on Node.js 22. Set up Jasmine 7, write specs with matchers and hooks, replace dependencies with spies, and test async code and timers.
A JavaScript global variable is a property of globalThis or a top-level declaration in a classic script. Learn how var, let and const behave in scripts, ES modules and CommonJS, why strict mode rejects implicit globals, and how to type globals in TypeScript.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.