I'm trying to detect the data type and if that data type is string
then check if
it is double or single
quotes.
Let say i have two
strings:
var a =
"hello";
var b =
'hello';
How can i
detect if the string is double or single quotes in
javascript???
I have tried to do
so:
typeof
a
i get string as
output....but i don't know if that string is double or single quotes. I have also
searched a alot, but can't find how is that done.
Answer
I'm trying to
detect the data type and if that data type is string then check if it is double or
single
quotes.
You
can't, that information isn't retained in any way once parsing is complete. They're both
just strings. They are completely
indistinguishable.
The quotes are purely a
source code thing. They say "The text here isn't code, it's the content of a string."
Once the string is created at runtime, it's completely irrelevant what source code
created it — including the type of quotes used, or even if it was the result of
evaluating something else entirely (like a template literal or a function
call).
No comments:
Post a Comment