JS Reference

JS by Category JS by Alphabet

JavaScript

JS Array JS Boolean JS Classes JS Date JS Error JS Global JS JSON JS Math JS Number JS Operators JS RegExp JS Statements JS String

Window

Window Object Window Console Window History Window Location Window Navigator Window Screen

HTML DOM

DOM Document DOM Element DOM Attributes DOM Events DOM Event Objects DOM HTMLCollection DOM Style
alignContent alignItems alignSelf animation animationDelay animationDirection animationDuration animationFillMode animationIterationCount animationName animationTimingFunction animationPlayState background backgroundAttachment backgroundColor backgroundImage backgroundPosition backgroundRepeat backgroundClip backgroundOrigin backgroundSize backfaceVisibility border borderBottom borderBottomColor borderBottomLeftRadius borderBottomRightRadius borderBottomStyle borderBottomWidth borderCollapse borderColor borderImage borderImageOutset borderImageRepeat borderImageSlice borderImageSource borderImageWidth borderLeft borderLeftColor borderLeftStyle borderLeftWidth borderRadius borderRight borderRightColor borderRightStyle borderRightWidth borderSpacing borderStyle borderTop borderTopColor borderTopLeftRadius borderTopRightRadius borderTopStyle borderTopWidth borderWidth bottom boxShadow boxSizing captionSide caretColor clear clip color columnCount columnFill columnGap columnRule columnRuleColor columnRuleStyle columnRuleWidth columns columnSpan columnWidth counterIncrement counterReset cursor direction display emptyCells filter flex flexBasis flexDirection flexFlow flexGrow flexShrink flexWrap cssFloat font fontFamily fontSize fontStyle fontVariant fontWeight fontSizeAdjust height isolation justifyContent left letterSpacing lineHeight listStyle listStyleImage listStylePosition listStyleType margin marginBottom marginLeft marginRight marginTop maxHeight maxWidth minHeight minWidth objectFit objectPosition opacity order orphans outline outlineColor outlineOffset outlineStyle outlineWidth overflow overflowX overflowY padding paddingBottom paddingLeft paddingRight paddingTop pageBreakAfter pageBreakBefore pageBreakInside perspective perspectiveOrigin position quotes resize right scrollBehavior tableLayout tabSize textAlign textAlignLast textDecoration textDecorationColor textDecorationLine textDecorationStyle textIndent textOverflow textShadow textTransform top transform transformOrigin transformStyle transition transitionProperty transitionDuration transitionTimingFunction transitionDelay unicodeBidi userSelect verticalAlign visibility width wordBreak wordSpacing wordWrap widows zIndex

Web APIs

API Console API Fullscreen API Geolocation API History API MediaQueryList API Storage

HTML Objects

<a> <abbr> <address> <area> <article> <aside> <audio> <b> <base> <bdo> <blockquote> <body> <br> <button> <canvas> <caption> <cite> <code> <col> <colgroup> <datalist> <dd> <del> <details> <dfn> <dialog> <div> <dl> <dt> <em> <embed> <fieldset> <figcaption> <figure> <footer> <form> <head> <header> <h1> - <h6> <hr> <html> <i> <iframe> <img> <ins> <input> button <input> checkbox <input> color <input> date <input> datetime <input> datetime-local <input> email <input> file <input> hidden <input> image <input> month <input> number <input> password <input> radio <input> range <input> reset <input> search <input> submit <input> text <input> time <input> url <input> week <kbd> <label> <legend> <li> <link> <map> <mark> <menu> <menuitem> <meta> <meter> <nav> <object> <ol> <optgroup> <option> <output> <p> <param> <pre> <progress> <q> <s> <samp> <script> <section> <select> <small> <source> <span> <strong> <style> <sub> <summary> <sup> <table> <tbody> <td> <tfoot> <th> <thead> <tr> <textarea> <time> <title> <track> <u> <ul> <var> <video>

Other References

CSSStyleDeclaration JS Conversion


자바스크립트 기능

예시

호출될 때 "Hello World"를 출력하는 함수를 선언합니다.

// Declare a function
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World!";
}

// Call the function
myFunction();

아래에 더 많은 예가 있습니다.


정의 및 사용

명령문 은 function함수를 선언합니다.

선언된 함수는 "나중에 사용하기 위해 저장"되며 나중에 호출(호출)될 때 실행됩니다.

JavaScript에서 함수는 객체이며 속성과 메서드를 모두 가지고 있습니다.

함수는 표현식을 사용하여 정의할 수도 있습니다( 함수 정의 참조 ).

함수에 대해 알아야 할 모든 것을 배우려면 JavaScript 자습서를 읽으십시오. JavaScript 함수JavaScript 범위 에 대한 소개 장부터 시작하십시오 . 더 자세한 정보는 함수 정의 , 매개변수 , 호출클로저 에 대한 함수 섹션을 참조하십시오 .

또한보십시오:

반환 문 .


통사론

function functionName(parameters) {
  code to be executed
}

매개변수

Parameter Description
functionName Required.
The name of the function.
Naming rules: same as JavaScript variables.
parameters Optional.
A set of arguments (parameter names), separated by commas.

The arguments are real values received by the function from the outside.
Inside the function, the arguments are used as local variables.

If a function is called with a missing argument, the value of the missing argument is set to undefined.


더 많은 예

PI 값을 반환합니다.

function myFunction() {
  return Math.PI;
}

a와 b의 곱을 반환합니다.

function myFunction(a, b) {
  return a * b;
}

인수가 다른 함수는 다른 결과를 생성할 수 있습니다.

화씨를 섭씨로 변환:

function toCelsius(fahrenheit) {
  return (5/9) * (fahrenheit-32);
}

함수를 변수로 사용할 수 있습니다.

대신에:

temp = toCelsius(32);
text = "The temperature is " + temp + " Centigrade";

당신이 사용할 수있는:

text = "The temperature is " + toCelsius(32) + " Centigrade";

JavaScript 함수에는 인수라는 내장 객체가 있습니다.

arguments.length 속성은 함수에서 수신한 인수의 수를 반환합니다.

function myFunction(a, b) {
  return arguments.length;
}

"Hello World"를 출력하는 함수를 호출하려면 클릭하세요.

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}
</script>

함수 표현식이 변수에 저장되면 변수에는 다음과 같은 함수가 포함됩니다.

const x = function (a, b) {return a * b};

함수가 변수에 저장되면 변수를 함수로 사용할 수 있습니다.

const x = function (a, b) {return a * b};
let z = x(4, 3);

관련 페이지

JavaScript 튜토리얼: JavaScript 함수

JavaScript 튜토리얼: JavaScript 범위

JavaScript 튜토리얼: JavaScript 함수 정의

JavaScript 튜토리얼: JavaScript 함수 매개변수

JavaScript 튜토리얼: JavaScript 함수 호출

JavaScript 튜토리얼: JavaScript 함수 클로저

JavaScript 참조: JavaScript return 문


브라우저 지원

function ECMAScript1(ES1) 기능입니다.

ES1(JavaScript 1997)은 모든 브라우저에서 완벽하게 지원됩니다.

Chrome IE Edge Firefox Safari Opera
Yes Yes Yes Yes Yes Yes