Monday, July 11, 2016

Difference between single quotes and double quotes in Javascript

You'll want to use single quotes where you want double quotes to appear inside the string (e.g. for html attributes) without having to escape them, or vice versa. Other than that, there is no difference.
I wouldn't say there is a preferred method. You can use either. However, if you are using one form of quote in the string, you might want to use the other as the literal.
alert('Say "Hello"');

alert("Say 'Hello'");