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>"
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 thename
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 thecolor
attribute set to the given color -
.fontsize(size)
: Returns the string wrapped in<font>
tags with thesize
attribute set to the given size -
.italics()
: Returns the string wrapped in<i>
tags. -
.link(url)
: Returns the string wrapped in<a>
tags with thehref
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)
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...
I appreciate the feedback, and you're absolutely right. I've gone ahead and edited in a more prominent disclaimer. Thank you!
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.
I'm going to use one of these today in my code :D :D
😱
Wow I just found out those tricks.