Unicode javascript

Asked
Active3 hr before
Viewed126 times

5 Answers

javascriptunicode
90%

Unicode property escapes,A blog post from Axel Rauschmayer about Unicode property escapes,Regular expressions guide Character classes Assertions Quantifiers Groups and ranges ,Unicode character property — Wikipedia

Example_snippet/controller/utility/_javascript.js/ // Non-binary values \p{Unicod. . .
// Non-binary values
\
p {
   UnicodePropertyValue
}\
p {
   UnicodePropertyName = UnicodePropertyValue
}

// Binary and non-binary values
\
p {
   UnicodeBinaryPropertyName
}

// Negation: \P is negated \p
\
P {
   UnicodePropertyValue
}\
P {
   UnicodeBinaryPropertyName
}
load more v
88%

ECMAScript 2015 provides escape sequences that represent code points from the entire Unicode space: U+0000 to U+10FFFF, i,e

Example_snippet/controller/utility/_javascript.js/ console.log('\uD83D\uDE00'); /. . .
console.log('\uD83D\uDE00'); // => '😀'
load more v
72%

Using Unicode in a string,Unicode encoding of source files,ES6 Unicode code point escapes,How JavaScript uses Unicode internally

Example_snippet/controller/utility/_javascript.js/ Content-Type: application/java. . .
Content - Type: application / javascript;
charset = utf - 8
Step 2 continued with <script src="./app.js" charset. . .
<script src="./app.js" charset="utf-8">
Step 3 continued with ... <head> <meta charset="ut. . .
...

<head>
   <meta charset="utf-8" />
</head>
...
Step 4 continued with const s1 = '\u00E9' //é . . .
const s1 = '\u00E9' //é
Step 5 continued with const s2 = '\u0065\u0301' //é. . .
const s2 = '\u0065\u0301' //é
Step 6 continued with s1.length //1 s2.length //2 . . .
s1.length //1
s2.length //2
Step 7 continued with const s3 = 'e\u0301' //é s3.l. . .
const s3 = 'e\u0301' //é
s3.length === 2 //true
s2 === s3 //true
s1 !== s3 //true
Step 8 continued with const s1 = '\u00E9' //é const . . .
const s1 = '\u00E9' //é
const s3 = 'e\u0301' //é
s1 !== s3
Step 9 continued with s1.normalize() === s3.normaliz. . .
s1.normalize() === s3.normalize() //true
Step 10 continued with const s4 = '🐶' . . .
const s4 = '🐶'
Step 11 continued with '👩‍❤️‍👩'.length . . .
'👩‍❤️‍👩'.length
Step 12 continued with ;[...'🐶'].length //1 . . .
;
[...'🐶'].length //1
Step 13 continued with require('punycode').ucs2.decod. . .
require('punycode').ucs2.decode('🐶').length //1
Step 14 continued with require('punycode').ucs2.decod. . .
require('punycode').ucs2.decode('👩‍❤️‍👩').length //6
[...'👩‍❤️‍👩'].length //6
Step 15 continued with '\u{XXXXX}' . . .
'\u{XXXXX}'
Step 16 continued with '\x61' // a '\x2A' // * . . .
'\x61' // a
'\x2A' // *
load more v
65%

You can also construct a character using the String,fromCharCode() method, passing as a parameter the Unicode number, in decimal as in var Omega = String

Example_snippet/controller/utility/_javascript.js/ var Omega = '\u03A9'; . . .
var Omega = '\u03A9';
load more v
75%

In Javascript, the identifiers and string literals can be expressed in Unicode via a Unicode escape sequence, The general syntax is \uXXXX, where X denotes four hexadecimal digits

Example_snippet/controller/utility/_javascript.js/ var f\u006F\u006F = 'abc'; con. . .
var f\u006F\u006F = 'abc';
console.log(foo)
load more v