Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var name = 'John Doe';
- // normal string
- var greet = 'Hello ' + name;
- // Template literal
- var greet2 = `Hello ${ name }`;
- // also add this in a seperate same-level jsconfig.js file to make sure Node compiles it correctly
- {
- "compilerOptions": {
- "target": "ES6"
- }
- }
- // USING TEMPLATE LITERAL IN AN OBJECT CALL //
- /////////////////////////////////////////////
- var obj = {
- name: 'Scooby Doo',
- greet: function(){
- // this will refer to the obj
- console.log(`Hello, ${ this.name }`);
- }
- }
- // will return the greet property of obj which is using obj literal to reference name
- obj.greet();
- // to overwrite name property
- obj.greet.call({ name: 'Jane Doo'});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement