JavaScript String bold(): Legacy Reference

String.prototype.bold() is a deprecated HTML-wrapper method retained for compatibility. Do not use it for new code. Use semantic HTML such as <strong>, CSS, or DOM APIs instead.

const text = "Important";
console.log(text.bold()); // legacy: <b>Important</b>

Legacy bold() syntax Top ↑

string.bold()

The method returns an HTML string; it does not style the original JavaScript string object.

Legacy output Top ↑

const text = "Welcome to Plus2net";
const htmlText = text.bold();
console.log(htmlText);

Preferred semantic HTML Top ↑

If the text has strong importance, write <strong>Important</strong> directly in HTML.

Modern DOM approach Top ↑

const strong = document.createElement("strong");
strong.textContent = "Important";
document.body.append(strong);

Using textContent avoids interpreting the text itself as HTML.

Use CSS for visual boldness only Top ↑

.emphasis { font-weight: 700; }

Use CSS when the effect is visual rather than semantic.

Common mistakes Top ↑

Do not build user-supplied HTML with deprecated wrapper methods and then insert it with innerHTML. Prefer DOM creation and textContent.

Previous / String Reference Next related topic




Subscribe to our YouTube Channel here



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer