Example 1 — Basic new Text()
Create a text node and inspect its content and type.
const text = new Text("Test");
console.log(text.data); // "Test"
console.log(text.nodeName); // "#text"
console.log(text.nodeType); // 3
console.log(text instanceof Text); // true How It Works
- Call the constructor. Pass the string you want as content.
- Read
data. That is the node’s textual content. - Check identity.
nodeNameis"#text";nodeTypeis3. - Still detached. Nothing appears on the page until you append it.

