Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Knowledge base — JavaScript

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 1003

JavaScript

Measuring an element’s bounding rectangle height

`getBoundingClientRect()` measures an element’s geometry relative to the viewport. Read `DOMRect.height` to get the rectangle’s height in CSS pixels.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element bounding rectangles and client offsets

Measure an element’s position and size relative to the viewport, and distinguish those measurements from the left and top offsets of its client area.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element.hasAttribute() and Element.scrollIntoView()

Check whether an element has a named attribute and use the result to decide whether to scroll to it. Distinguish attribute presence from its value, and scrolling from setting focus.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element.innerHTML and text insertion security boundaries

Choose between parsing markup and inserting literal text. Learn how to prevent DOM XSS and what changes when Trusted Types are enforced.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element.innerHTML and Element.className

Use `innerHTML` to read or replace an element’s contents, and `className` to read or set its CSS classes.

Intermediate · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element.innerHTML, tagName, and namespaceURI

Read and replace an element’s markup, and distinguish elements by local name and namespace when HTML and SVG share the same DOM tree.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Element: select descendants, check attributes, and measure rectangles

Use `querySelectorAll()` to find matching descendants, `hasAttribute()` to check whether an attribute is present, and `getClientRects()` to read layout geometry. None of these results alone tells you whether the user can see an element.

Intermediate · Current web platform; runtime support varies
JavaScript

Element.replaceChildren() and Element.className

Replace or clear all of an element’s child nodes, and read or set its entire `class` attribute without changing its children.

Intermediate · Current web platform; runtime support varies
JavaScript

Event loop microtask checkpoints and timer tasks

In browsers, `queueMicrotask()` and Promise reactions share a microtask queue. `setTimeout()` schedules a separate task, even with a delay of `0`.

Intermediate · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

One-shot event listeners with `once`

Use `{ once: true }` to make an event listener run at most once per registration. The registration is removed before its callback runs.

Advanced · Current web platform; runtime support varies
JavaScript

The `passive` option in `EventTarget.addEventListener()`

`passive: true` lets a listener receive the event without being able to cancel its default action. Leaving the option out is not always equivalent to passing `false`.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Event.target and capture listeners

Tell the event’s target apart from the object running the listener, and see how the `capture` option changes listener order in the DOM.

Intermediate · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Event.target and Event.type

`event.target` identifies the event’s target, while `event.type` gives its name. `event.currentTarget` identifies the object on which the running listener was registered.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Function declaration hoisting in JavaScript

A `function` declaration can be called before it appears in source code. A function expression used as an initializer does not make its function available the same way.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

`Function.length` and function arity

`fn.length` describes a function's expected arity, while `arguments.length` counts the arguments supplied in a particular call.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Function.prototype and class constructor syntax

Distinguish a function's own prototype chain from the `.prototype` property used to create instances, and see how `new`, `constructor`, and `super()` fit into inheritance.

Advanced · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Function.prototype and prototype-method assignment

Distinguish a function’s own prototype chain from the prototype of its instances, and share one method across those instances.

Intermediate · ECMAScript 2024 and the current web platform; runtime support varies
JavaScript

Function.prototype.prototype — why it reads as undefined

In an unmodified environment, reading `Function.prototype.prototype` gives `undefined`. That does not mean `Function.prototype` has no internal prototype.

Intermediate · ECMAScript 2024 and the current web platform; runtime support varies