Thursday, March 22, 2018

Special Characters in Javascript

Below list of some special characters,

Character Description

\b                            Backspace
\f                            Form feed
\n                            New line
\r                            Carriage return
\t                            Tab

\uNNNN                    A unicode symbol with the hex code NNNN, for instance \u00A9 – is a
                                    unicode  the copyright symbol ©. It must be exactly 4 hex digits.

\u{NNNNNNNN}     Some rare characters are encoded with two unicode symbols, taking up to 4                                           bytes. This long unicode requires braces around it.


alert( "\u00A9" ); // It will print you copyright symbol.

alert( "\u{1F60D}" ); // It will print you smiley symbol.


All special characters should start with backslash \'.

Example I :


let specialList = "Specials:\n * One\n * Two\n * Three";

alert(specialList);
//Output: Specials:
* One
* Two
* Three



Example II :


alert( 'I\'m the World!' ); // I'm the world!

we have to prep-end the inner quote by the backslash \'. Else javascript will consider that as string end. So that we should add backslash.


Example III :


alert( `Adding backslash symbol: \\` ); // Output : Adding backslash symbol: \


To add backslash symbol in your string add lie above.





1 comment:

  1. Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. 经济代写

    ReplyDelete