-1

There are certain ways to print letters in javascript using unicode FOr example

console.log(\u0062) yields a b , so its the same as putting console.log(b)

But now, I do know there are certains way to console.log bold letters, for example

console.log('')

prints a bold word in the console.

But what would be a function for example to print in bold?

THis is my idea

const printBold = (word: string) => {
  //splits the string, gets every letter, and replaces with the bold unicode equivalent
} 

But... im unable to find a unicode equivalent for bold letters, or a way to create a function that logs in bold.

Maybe I can do something like

const map = {
 "a": "bold_a",
 "b": ''
}

And feed the converter with that data, but... where do I get the bold unicodes or characters from? THe only ones I could find, i copied them from this answer https://stackoverflow.com/a/70569635/9010895

mouchin777
  • 1,428
  • 1
  • 31
  • 59
  • 3
    **Danger**: Those are not bold **letters**, they are mathematic symbols designed for writing equations. Trying to use them as bold letters will play havock with screen readers and search engines. – Quentin Dec 23 '22 at 12:25
  • 1
    You'd look at a Unicode table that contains these characters: https://unicode-table.com/en/blocks/mathematical-alphanumeric-symbols/. But as noted above, **they're not equivalent to the word "bold"**, they have as much in common as if you wrote ボルド. – deceze Dec 23 '22 at 12:29

1 Answers1

4

Your current approach is seriously flawed. Those are not bold letters, they are mathematic symbols designed for writing equations. Trying to use them as bold letters will play havock with screen readers.

The console does have features for formatting text which you should use instead.

You can use a format specifier:

const bold = "font-weight: bold";
const normal = "font-weight: normal";
console.log("A string with a %cbold%c word", bold, normal);

Or an ANSI escape sequence

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335