Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you think you have some skills to help others

help someone and become a part of our community - List Q & A

JavaScript - insert unicode character to string

0 contributions
3 points

In this article we are goring to look at how to insert unicode character to string in JavaScript.

There are available three different ways how to do it:

  • with escape character e.g. \u03c0 that is equal to π,
  • by pasting character directly to string,
  • by converting codes to string.

Quick solution:

// ONLINE-RUNNER:browser;

var text = "π or \u03c0"; // U+03C0

console.log(text); // π or π

Note: it is important to put 4 digits after \u.

More complicated example

Space is represented by 0x20 (in hex) or 32 (in dec). It is necessary to add 2 aditional zeros before code (e.g. \u0020).

// ONLINE-RUNNER:browser;

var text = "π and \u03c0 are\u0020equal"; // U+03C0 U+0020

console.log(text); // π and π are equal

Marked inserted unicode characters: π and \u03c0 are\u0020equal.

Note: read this article to see more examples.

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more