ascii - Dynamic vs Direct Octal Character Representation in JavaScript -
if create 3 digit octal character string following way:
x = "\\" + + b + c
where a either 0 or 1, , b , c both number 0 7, why alert(x) result in \141 example, , not a alert("\141")?
second this, how original created character code result in respective ascii character?
why alert(x) result in \141 example, , not alert("\141")?
because inside string literal, \\ , \ different things. first creates actual backslash in string, whereas in second example, backslash introduces octal escape sequence. it's same reason \\n in string literal backslash followed letter n, \n newline.
or more simply: because you're doing nothing tries reinterpret you've created string literal. it's string, , nothing tries evaluate characters inside using string literal rules second time.
how original created character code result in respective ascii character
if i'm understanding question correctly, 2 ways:
strip off
\\, convert remainder of string number viaparseint(..., 8)(octal), , usestring.fromcharcode.use
eval. don't this, #1
side note: octal escape sequences aren't part of standard javascript, although in loose mode implementations are allowed, not required, support them. they're not allowed in strict mode @ all.
Comments
Post a Comment