What is the difference between 'xxx' and xxx
?
For example in below code:
namespace = 'api';
...
return `${super.buildURL(...args)}.json`;
What is the difference between 'xxx' and xxx
?
For example in below code:
namespace = 'api';
...
return `${super.buildURL(...args)}.json`;
Single quotes is just a string literal, whereas backticks allow you to refer to other variables (or functions) inline via the $ and {} or () characters.
Also newlines are interpretted differently in each type. With quote marks, you need to use \n for newlines, whereas backtick strings are WYSIWYG with regard to newlines. You can also use double quotes as well. This is useful when you want to actually use quote marks in your strings, for example:
var my_string = '"Hello", she said.';
console.log("mystring:" + my_string);
would produce:
mystring: "Hello", she said.
This is one of the most useful things I find about the mixing of quote marks for strings, you can use the other style of quote without having to escape it! Makes code so much more readable.