DEV Community

Cover image for TIL About .bold(), .blink(), and More JavaScript String Methods
Ben Myers
Ben Myers

Posted on

TIL About .bold(), .blink(), and More JavaScript String Methods

While playing around in the Chrome DevTools, I noticed a string method I had never seen before: .bold(). Curiosity got the better of me, and I gave it a try.

let myString = 'Hello World!';
myString.bold(); // returns "<b>Hello World!</b>"
Enter fullscreen mode Exit fullscreen mode

It's a method that returns the string wrapped in a <b> tag. It's very deprecated, but all major browsers still support it.

.bold() is not alone - I've found several other string methods that are in the same boat. Again, these are all deprecated, and should not be used in the wild.

  • .anchor(name): Returns the string wrapped in <a> tags with the name attribute set to the given name
  • .big(): Returns the string wrapped in <big> tags.
  • .fixed(): Returns the string wrapped in <tt> tags.
  • .fontcolor(color): Returns the string wrapped in <font> tags with the color attribute set to the given color
  • .fontsize(size): Returns the string wrapped in <font> tags with the size attribute set to the given size
  • .italics(): Returns the string wrapped in <i> tags.
  • .link(url): Returns the string wrapped in <a> tags with the href attribute set to the given URL
  • .small(): Returns the string wrapped in <small> tags.
  • .strike(): Returns the string wrapped in <strike> tags.
  • .sub(): Returns the string wrapped in <sub> tags.
  • .sup(): Returns the string wrapped in <sup> tags.

... and, of course, my personal favorite: .blink(), which returns your string wrapped in a <blink>.

As with .bold(), these methods are all officially deprecated. Several of them even wrap your strings in tags that have long since been deprecated. These methods remain in browsers for the sake of backwards compatibility, an artifact of development past.

Top comments (7)

Collapse
 
michelc profile image
Michel • Edited

The String object has so many methods: developer.mozilla.org/en-US/docs/W....

Maybe it would be better to emphasize "these methods are all officially deprecated" and write it in bold...

Collapse
 
bendmyers profile image
Ben Myers

I appreciate the feedback, and you're absolutely right. I've gone ahead and edited in a more prominent disclaimer. Thank you!

Collapse
 
dexygen profile image
George Jempty • Edited

I think you might find this interesting too if you don't already know it. Let's say you have an element in your page with the id of "foobar" -- well then there will be a global variable named "foobar" that points to this element.

Collapse
 
rubenofen profile image
rubenofen

I'm going to use one of these today in my code :D :D

Collapse
 
bendmyers profile image
Ben Myers

😱

Collapse
 
mzaini30 profile image
Zen

Wow I just found out those tricks.