What does ' ', and " ", and no quotes mean in Javascript?
' '
and " "
are the same thing; they are used to define string literals.
Things without quotes can be an identifier, keyword, non-string literal, property name or a number (may have missed one).
Examples:
"hello world" literal (string)
'hello world' literal (string) with same contents
document identifier (object)
{ a: 1 } property name
if keyword (start conditional statement)
3.4 literal (number)
/abc/ literal (regex object)
String literals that are enclosed in single quotes don't need escaped double quotes and visa versa, e.g.:
'<a href="">click me</a>' HTML containing double quotes
"It's going to rain" String containing single quote
' '
and " "
used to quote string literal and represents string(s) whereas literal without quote are variables (name of variable, constant) know as identifier, example
variable = 'Hello'; (Here `variable` is identifier and 'Hello' is string literal)
var = "Ho There"
You might question, what is the difference between ' (single quote)
and " (Double quote)
Difference is ,strings within "
if have special character then they need to escape. Example:
Variable = "hi " there"; ---> here you need to escape the "
inside string like
Variable = "hi \" there";
But if using, '
then no need of escaping (unless there is a extra '
in string). You can hve like
var = 'Hello " World"';
"
and '
are interchangeable (but need to be used together).
myObject["property"]
and myObject.property
are also interchangeable. $var foo = "property"; myObject[foo]
as well (per comment below).