JavaScript #5 - template literals & string method

Haebin Ethan Jeong·2020년 7월 22일
0

Template Literals

  • Before, when we write a string, we used quotation marks, but we can also use back tick for strings.
  • For example,
const name = 'ethan';
const hi = `Hello. I'm ${name}.`;
  • Normally, You can't write strings with multiple sentences like below:
let detail = 'Hello. 
I'm
Ethan';
console.log(detail); >>>> ERROR!!

Rather, you should do like this:
let detail = 'Hello.\n'+'I'm\n'+'Ethan';

HOWEVER, in template literal, you can write strings with multiple sentences.

String Method

  • startsWith
  • endsWith
  • includes
const email = 'yealee.kim87@gmail.com';

console.log(email.startsWith('ye'));
console.log(email.endsWith('com'));
console.log(email.includes('@gmail'));

Accessing String with []

Getting substrings

Other helpful methods

profile
I'm a Junior studying Economics and Computer Science at Vanderbilt University.

0개의 댓글