๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
JAVASCRIPT

[JAVASCRIPT] ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด

by _ํ† ๋งคํ†  2022. 8. 18.
728x90

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ : ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด

์ง€๊ธˆ๋ถ€ํ„ฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ๊ณผ ๋ฌธ์ž์—ด ๋ฉ”์†Œ๋“œ์ธ ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ์•Œ์•„๋ด…์‹œ๋‹ค!


1. ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด

ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด( )์€ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ ๋ฉ”์„œ๋“œ๋กœ ๋‚ด์žฅ๋œ ํ‘œํ˜„์‹์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด์ž…๋‹ˆ๋‹ค.
๋ฌธ์ž์—ด์„ ๊ฒฐํ•ฉํ•  ๋•Œ ๋”ฐ์˜ดํ‘œ ๋Œ€์‹  ` ` (backtick_๋ฐฑํ‹ฑ)์„ ์‚ฌ์šฉํ•˜๋ฉฐ ๋ณ€์ˆ˜๋ฅผ ๋„ฃ๊ณ ์ž ํ•˜๋Š” ๋ถ€๋ถ„์— ${}๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ„๋‹จํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฌธ๋ฒ•์„ ๋ฌธ์ž์—ด ์•ˆ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

//01. ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ
const str1 = "์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ";
const str2 = "์ œ์ดํ€˜๋ฆฌ";
document.querySelector(".sample01_P1").innerHTML = str1 + str2;

//02. ์ˆซ์ž(number) ๊ฒฐํ•ฉ
const num1 = 100;
const num2 = 200;
document.querySelector(".sample01_P2").innerHTML = num1 + num2;

//03. ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉํ•œ ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ
//๋ฌธ์ž์—ด์ธ (modern)๊ณผ (javascript) ์ถ”๊ฐ€ํ•˜๊ธฐ
//๋‚˜๋Š” ๋ชจ๋˜(modern) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(javascript) ํ•ต์‹ฌ์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค.
const text1 = "๋ชจ๋˜";
const text2 = "์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ";
const text3 = "ํ•ต์‹ฌ";
//์ผ๋ฐ˜ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ
document.querySelector(".sample01_P3").innerHTML = "๋‚˜๋Š” " + text1 + "(modern) " + text2 + "(javascript) " + text3 + "์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค.";
//๋ฐฑํ‹ฑ๊ณผ ${} ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅ
document.querySelector(".sample01_P4").innerHTML = `๋‚˜๋Š” ${text1}(modern) ${text2}(javascript) ${text3}์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค.`;
ํ‘œ๋กœ ํ™•์ธํ•ด๋ณด์ž!
๋ฒˆํ˜ธ ๊ธฐ๋ณธ๊ฐ’ ๋ฉ”์„œ๋“œ ๋ฆฌํ„ด๊ฐ’
1 ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ, ์ œ์ด์ฟผ๋ฆฌ ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์ œ์ดํ€˜๋ฆฌ
2 100, 200 ์ˆซ์ž(number) ๊ฒฐํ•ฉ 300
3 ๋ชจ๋˜, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ, ํ•ต์‹ฌ ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ ๋‚˜๋Š” ๋ชจ๋˜(modern) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(javascript) ํ•ต์‹ฌ์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค.
4 ๋ชจ๋˜, ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ, ํ•ต์‹ฌ ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ ๋‚˜๋Š” ๋ชจ๋˜(modern) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(javascript) ํ•ต์‹ฌ์„ ๋ฐฐ์šฐ๊ณ  ์‹ถ๋‹ค.

! point !
"" ํฐ ๋”ฐ์˜ดํ‘œ๋กœ๋„ ์ถœ๋ ฅ์ด ๊ฐ€๋Šฅํ•˜์ง€๋งŒ ์ฝ”๋“œ๊ฐ€ ์ง๊ด€์ ์ด์ง€ ์•Š๊ณ  ๋ณต์žกํ•˜๋‹ค. ๋•Œ๋ฌธ์— ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ ๋” ๊ฐ€๋…์„ฑ ์žˆ๊ฒŒ ์ฝ”๋“œ๋ฅผ ์งœ๋ณด๋„๋ก ํ•˜์ž!

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css