How Do You Render HTML Strings with dangerouslySetInnerHTML?
Use dangerouslySetInnerHTML with an __html object to render HTML strings in React. Learn why it is risky, how to sanitise input and what to use instead.
466 posts about JavaScript: questions with answers, tutorials and articles, newest first.
Use dangerouslySetInnerHTML with an __html object to render HTML strings in React. Learn why it is risky, how to sanitise input and what to use instead.
Dynamic import() returns a promise for a module namespace. See how to use it from CommonJS, for lazy loading, plugins and JSON.
Type coercion is JavaScript converting values between types automatically. See the rules for +, ==, conditions and objects, with examples.
React may call your component any time and more than once, so rendering must be a pure calculation. See what breaks purity and where side effects should go.
Node.js walks up parent folders looking for node_modules, then picks a file using exports or main. Learn the rules and how to debug them.
Learn the main ways to convert a number to a string in JavaScript, when each one fits, and how to control decimals and locale formatting.
The React component tree is the nested hierarchy of components in your app. See how React renders it, passes props down it and re-renders branches after state changes.
HTML data attributes store custom values on any element. See the naming rules, how to read and write them in JavaScript and CSS, and common pitfalls.
Node.js loads each module once and reuses its exports. See how require.cache works, how to clear it, and how ES modules differ.
Compare Number(), parseInt(), parseFloat() and the unary plus for converting strings to numbers, and see how to check for NaN safely.
Use the React children prop to build wrapper and layout components, add extra slots with named props, and type children in TypeScript.
__dirname is not defined in ES modules. Use import.meta.dirname and import.meta.filename, or fileURLToPath with import.meta.url on older Node.js.
A Symbol is a unique primitive value. Learn how to create one, use it as an object key and hook into the language with well-known symbols.
Pass an object with camelCase keys to the style prop to apply inline styles in React, and learn when CSS classes are the better choice.
Set type module in package.json so .js files become ES modules. Learn how .mjs and .cjs override it and how to fix errors after switching.
A practical guide to the modular AWS SDK for JavaScript v3: clients, commands, credentials, S3 and DynamoDB examples, pagination and v2 migration.
BigInt stores whole numbers of any size exactly. Learn how to create and use it, its limits with JSON and Math, and when to prefer Number.
JSX uses className because class is a reserved JavaScript word. Learn how to build dynamic class lists and other renamed attributes.
Compare CommonJS and ES modules in Node.js: syntax, sync versus async loading, live bindings, interoperability and a migration checklist.
0.1 + 0.2 gives 0.30000000000000004 because binary floats cannot store those decimals exactly. Learn the cause and the reliable fixes.