Coding/JavaScript

[JavaScript] ๋ฌธ์ž์—ด

ํ˜ธ๋ฐ€์ด 2022. 4. 27. 20:06

๐Ÿ“Œ ๋ฌธ์ž์—ด: ''(๋”ฐ์˜ดํ‘œ)๋กœ ๊ฐ์‹ธ์ง„ ๋ฐ์ดํ„ฐ ๊ฐ’

let name = "cho";

console.log(name);  // output: 'cho'

 

๐Ÿ“Œ ๋ฌธ์ž์—ด ๋‚ด ํŠน์ˆ˜๋ฌธ์ž ์‚ฌ์šฉ๋ฒ• 

์ผ๋ฐ˜์ ์œผ๋กœ ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•˜๋“ฏ์ด ํ•˜๋ฉด JS๋‚ด์—์„œ๋Š” ์ž‘์„ฑ๋˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. 

์œ„์™€ ๊ฐ™์€ ๊ฒฝ์šฐ JS๋‚ด์—์„œ ํŠน์ˆ˜๋ฌธ์ž๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ธฐํ˜ธ๋“ค์ด ๋งŽ์ด ์กด์žฌํ•˜๋Š”๋ฐ ๊ทธ ์ค‘ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ฌธ์ž๋ฅผ ์ž‘์„ฑํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

ํŠน์ˆ˜๋ฌธ์ž ์„ค๋ช…
\n ๊ฐœํ–‰
\t ์ˆ˜ํ‰ ํƒญ
\b ๋ฐฑ ์ŠคํŽ˜์ด์Šค
\\ \ ๊ธฐํ˜ธ
\' '(์ž‘์€ ๋”ฐ์˜ดํ‘œ)
\" "(ํฐ ๋”ฐ์˜ดํ‘œ)

 

 

๐Ÿ“Œ ๋ฌธ์ž์—ด๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ

๋ฌธ์ž์—ด์—์„œ ์ž์ฃผ ์‚ฌ์šฉํ•˜๋Š” ๋ฉ”์„œ๋“œ๋“ค์ด์ง€๋งŒ ๋ฐฐ์—ด๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ๋„ ๋‹ค์ˆ˜ ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

  • concat(data1, data2, ...)
    • ์ฃผ๋กœ ๋ฐฐ์—ด์„ ์ด์–ด ๋ถ™์ผ๋•Œ ๋งŽ์ด ์‚ฌ์šฉํ•˜์ง€๋งŒ ๋ฌธ์ž์—ด์—์„œ๋„ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.
let name = "cho";
let age = "27";

console.log(name.concat(age));		// output: 'cho27'
  • length
    • ๋ฌธ์ž์—ด์˜ ๊ธธ์ด๋ฅผ ํ™•์ธํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
let name = "cho";

console.log(name.length);		// output: 3
  • indexof('๋ฌธ์ž', ์‹œ์ž‘ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ)
    • ๋ฌธ์ž์—ด์—์„œ ํ•ด๋‹นํ•˜๋Š” ๋ฌธ์ž์˜ ์ธ๋ฑ์Šค ๋ฒˆํ˜ธ๋ฅผ ์ฐพ์„ ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
    • ํ•ด๋‹น ๋ฌธ์ž๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋‹ค๋ฉด -1์„ return ํ•ฉ๋‹ˆ๋‹ค.
let a = "hello";

console.log(a.indexOf('l'));		// output: 2
console.log(a.indexOf('l', 3));		// output: 3
  • includes('์ฐพ์„ ๊ฐ’')
    • ๋ฌธ์ž์—ด์— ์ฐพ๋Š” ๊ฐ’์ด ์กด์žฌํ•˜๋ฉด true, ์กด์žฌํ•˜์ง€ ์•Š๋‹ค๋ฉด false๋ฅผ return ํ•ฉ๋‹ˆ๋‹ค.
let a = "hello";

console.log(a.includes('e'));	// output: true
console.log(a.includes('z'));	// output: false
  • split(์กฐ๊ฑด)
    • ํ•ด๋‹นํ•˜๋Š” ์กฐ๊ฑด์— ๋งž๊ฒŒ ๋ฌธ์ž์—ด์„ ์ž˜๋ผ๋‚ด ๋ฐฐ์—ด๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค..
let a = 'hello js world';

console.log(a.split(' '));		// output: ['hello', 'js', 'world'] ๊ณต๋ฐฑ์„ ๊ธฐ์ค€
  • substr(start, end)
    • ๋ฌธ์ž์—ด์˜ ์‹œ์ž‘ ์ธ๋ฑ์Šค๋ถ€ํ„ฐ ์ข…๋ฃŒ ์ธ๋ฑ์Šค ์ „ ๊นŒ์ง€ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.
let a = 'helloJs';

console.log(a.substring(1, 3));		// output: 'el'
console.log(a.substring(3));		// output: 'lojs'
  • toLowerCase(), toUpperCase()
    • ๋ฌธ์ž์—ด์„ ์†Œ๋ฌธ์ž, ๋Œ€๋ฌธ์ž๋กœ ๋ฐ”๊ฟ”์ค๋‹ˆ๋‹ค.
let a = 'abcdef';
let b = 'HELLO';

console.log(a.toUpperCase());	// output: 'ABCDEF'
console.log(b.toLowerCase());	// output: 'hello'

 

 

๐Ÿ“ ์ฐธ๊ณ ์ž๋ฃŒ

JavaScript MDN: if ...else

 

 

'Coding > JavaScript' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[JavaScript] ๋ฐฐ์—ด  (0) 2022.05.10
[JavaScript] ๋ฐ˜๋ณต๋ฌธ(for, while)  (0) 2022.04.28
[JavaScript] ์กฐ๊ฑด๋ฌธ  (0) 2022.04.27
[JavaScript] ํ•จ์ˆ˜  (0) 2022.04.26
[JavaScript] ๋ณ€์ˆ˜์™€ ๋ฐ์ดํ„ฐ ํƒ€์ž…  (0) 2022.04.26