inblog logo
|
{CODE-RYU};
    Javascript

    자바스크립트 기본

    Feb 26, 2024
    자바스크립트 기본
    Contents
    1. 변수 선언2. 함수3. 오브젝트4. 배열
     
    💡
    자바스크립트는 웹 페이지에 동적인 요소를 추가하고, 사용자와 상호작용하는 기능을 구현하는 데 사용되는 프로그래밍 언어
     

    1. 변수 선언

     
    <script> let n1 = 1; let s1 = "문자열"; let s2 = '문자열'; let s3 = `문자열 ${n1}`; let b1 = true; let u1 = null; let u2; // undifined 타입. 값이 없음이라는 키워드 </script>
     
    💡
    자바스크립트에는 const, var , let 등 자료 타입이 있지만 모든 타입을 담을 수 있는 let 타입을 사용한다.
     
     
     

    2. 함수

     
    <script> function add(n1, n2) { console.log(n1 + n2); } add(1, 2); function minus(n1, n2) { return n1 - n2; } let result = minus(1, 2); console.log(`result:${result}`); </script>
     
    함수를 생성하고 호출한다.
    notion image
     
     
    함수명을 생략하고 간단하게 만들 수 있다.
     
    <script> //익명함수 let m1 = function (n1, n2) { console.log(n1 + n2); }; m1(1, 2); // 람다식 let m2 = (n1, n2) => { console.log(n1 + n2); }; m2(1, 2); //람다 표현식(expression), 리턴이 있어야됨. 리턴은 생략가능 let m3 = (n1, n2) => n1 + n2; let r3 = m3(1, 2); console.log(r3); </script>
     

    3. 오브젝트

     
    <script> const person = { firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }; console.log(person); </script>
    notion image
     

    4. 배열

     
    <script> let hobby = ["축구", "농구"]; let user = { id: 1, username: "ssar", hobby: hobby }; console.log(user); let arr = [1, 2, 3]; console.log(arr); console.log(arr[0]); </script>
     
    notion image
     
    💡
    자바스크립트의 배열은 컬렉션 형태로 크기가 가변적이다.
    Share article

    {CODE-RYU};

    RSS·Powered by Inblog