pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ko/docs/Learn_web_development/Howto/Solve_JavaScript_problems

ณ ์ณ์•ผ๋˜๋Š” ํ”ํ•œ ๋ฌธ์ œ๋“ค์˜ ํ•ด๊ฒฐ์ฑ…์„ ์ œ์‹œํ•œ๋‹ค." />

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Solve common problems in your JavaScript code

๋‹ค์Œ์˜ ๋งํฌ๋“ค์€ ๋‹น์‹ ์˜ JavaScript ์ฝ”๋“œ๊ฐ€ ์ •์ƒ์ ์œผ๋กœ ์ž‘๋™ํ•  ์ˆ˜ ์žˆ๊ฒŒ ๊ณ ์ณ์•ผ๋˜๋Š” ํ”ํ•œ ๋ฌธ์ œ๋“ค์˜ ํ•ด๊ฒฐ์ฑ…์„ ์ œ์‹œํ•œ๋‹ค.

์ดˆ๋ณด์ž๋“ค์˜ ํ”ํ•œ ์‹ค์ˆ˜๋“ค

์ŠคํŽ ๋ง๊ณผ ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ์ œ๋Œ€๋กœ ํ•ด๋ผ

์ฝ”๋“œ๊ฐ€ ์ž‘๋™ํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ๋ฌด์–ธ๊ฐ€๊ฐ€ undefined๋ผ๊ณ  ๋ถˆํ‰ํ•˜๋ฉด ๋ชจ๋“  ๋ณ€์ˆ˜ ์ด๋ฆ„, ํ•จ์ˆ˜ ์ด๋ฆ„ ๋“ฑ์„ ์ •ํ™•ํ•˜๊ฒŒ ์ž…๋ ฅํ–ˆ๋Š”์ง€ ํ™•์ธํ•˜์‹ญ์‹œ์˜ค.

๋ฌธ์ œ๋ฅผ ์ผ์œผํ‚ค๋Š” ๋ช‡ ๊ฐ€์ง€ ์ผ๋ฐ˜์ ์ธ ๋‚ด์žฅ ๋ธŒ๋ผ์šฐ์ € ํ•จ์ˆ˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

์˜ฌ๋ฐ”๋ฅธ ์ž˜๋ชป๋œ
getElementsByTagName() getElementbyTagName()
getElementsByName() getElementByName()
getElementsByClassName() getElementByClassName()
getElementById() getElementsById()

์„ธ๋ฏธ์ฝœ๋ก ์˜ ์œ„์น˜

์„ธ๋ฏธ์ฝœ๋ก ์˜ ์œ„์น˜๊ฐ€ ์ž˜๋ชป ๋˜์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”. ์˜ˆ๋ฅผ๋“ค์–ด:

์˜ฌ๋ฐ”๋ฅธ ์ž˜๋ชป๋œ
elem.style.color = 'red'; elem.style.color = 'red;'

ํ•จ์ˆ˜

ํ•จ์ˆ˜์™€ ๊ด€๋ จํ•˜์—ฌ ์‹ค์ˆ˜ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ๋“ค์ด ๋งŽ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฐ€์žฅ ํ”ํ•œ ์‹ค์ˆ˜๋Š” ํ•จ์ˆ˜๋ฅผ ์„ ์–ธํ•˜๊ณ  ์–ด๋””์„œ๋„ ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด:

js
function myFunction() {
  alert("This is my function.");
}

์œ„ ์ฝ”๋“œ๋Š” ํ˜ธ์ถœํ•˜์ง€ ์•Š๋Š” ์ด์ƒ ์•„๋ฌด๊ฒƒ๋„ ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

js
myFunction();

ํ•จ์ˆ˜ ์Šค์ฝ”ํ”„

ํ•จ์ˆ˜๋Š” ๊ฐ์ž์˜ ์Šค์ฝ”ํ”„๊ฐ€ ์žˆ์Œ์„ ๋ช…์‹ฌํ•˜์„ธ์š” โ€” ๋ณ€์ˆ˜๋ฅผ ์ „์—ญ์œผ๋กœ ์„ ์–ธํ•˜๊ฑฐ๋‚˜ ํ•จ์ˆ˜์—์„œ ๊ฐ’์„ ๋ฆฌํ„ดํ•˜์ง€ ์•Š๋Š”ํ•œ ํ•จ์ˆ˜ ๋ฐ–์—์„œ ํ•จ์ˆ˜ ๋‚ด๋ถ€์— ์„ค์ •๋œ ๋ณ€์ˆ˜ ๊ฐ’์— ์ ‘๊ทผ ํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค. (์ฆ‰, ์–ด๋– ํ•œ ํ•จ์ˆ˜ ๋‚ด์—์„œ๋„ ์ ‘๊ทผ ์•ˆ๋จ)

๋ฆฌํ„ด ๋ฌธ ์ดํ›„ ์ฝ”๋“œ ์‹คํ–‰

ํ•จ์ˆ˜ ๋ฐ–์œผ๋กœ ๊ฐ’์„ ๋ฆฌํ„ดํ•  ๋•Œ, JavaScript ์ธํ„ฐํ”„๋ฆฌํ„ฐ๊ฐ€ ํ•จ์ˆ˜๋ฅผ ์™„์ „ํžˆ ๋น ์ ธ๋‚˜๊ฐ์„ ๋ช…์‹ฌํ•˜์„ธ์š”. โ€” ๋ฆฌํ„ด ๋ฌธ ์ดํ›„์— ์„ ์–ธ๋œ ์ฝ”๋“œ๋Š” ์ ˆ๋Œ€๋กœ ์‹คํ–‰๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์‚ฌ์‹ค, ๋ช‡๋ช‡ ๋ธŒ๋ผ์šฐ์ €๋“ค์€ (Firefox ์ฒ˜๋Ÿผ) ๋ฆฌํ„ด ๋ฌธ ์ดํ›„์— ์ฝ”๋“œ๊ฐ€ ์žˆ๋‹ค๋ฉด ๊ฐœ๋ฐœ์ž ์ฝ˜์†”์— ์—๋Ÿฌ ๋ฉ”์„ธ์ง€๋ฅผ ์ค๋‹ˆ๋‹ค. Firefox๋Š” "unreachable code after return statement" ๋ผ๊ณ  ์•Œ๋ ค์ค๋‹ˆ๋‹ค.

์˜ค๋ธŒ์ ํŠธ ํ‘œ๊ธฐ vs ์ผ๋ฐ˜์  ํ• ๋‹น

๋ณดํ†ต ์ž๋ฐ”์Šคํฌ๋ฆฝํ…Œ์–ด์„œ ๋ฌด์–ธ๊ฐ€๋ฅผ ํ• ๋‹นํ•˜๋ ค๊ณ  ํ• ๋•Œ, ๋‹จ์ผ ๋“ฑํ˜ธ ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ:

js
const myNumber = 0;

ํ•˜์ง€๋งŒ, ์ด ๋ฐฉ๋ฒ•์€ ์˜ค๋ธŒ์ ํŠธ์—์„  ๋™์ž‘ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. โ€” ์˜ค๋ธŒ์ ํŠธ์—์„  ๋ฉค๋ฒ„์™€ ๊ฐ’ ์‚ฌ์ด๋ฅผ ์ฝœ๋ก ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜๊ณ , ๊ฐ ๋ฉค๋ฒ„๋“ค์€ ์ฝค๋งˆ๋กœ ๊ตฌ๋ถ„ํ•ฉ๋‹ˆ๋‹ค, ์˜ˆ๋ฅผ ๋“ค์–ด:

js
const myObject = {
  name: "Chris",
  age: 38,
};

๊ธฐ๋ณธ ์ •์˜

Basic use cases

General

Variables

Math

Strings

Arrays

Debugging JavaScript

For more information on JavaScript debugging, see Handling common JavaScript problems(en-US); also see Other common errors for a description of common errors.

Making decisions in code

Looping/iteration

Intermediate use cases

Functions

Objects

JSON

Events

Object-oriented JavaScript

Web APIs

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy