JS 함수 호출


function basicFuntion() {
    console.log("hello wolrd");
}

function basicFuntion() {
    console.log("hello wolrd");
}

const variableFunction2 = () => {
    console.log("hello wolrd");
}

const returnFunction = () => {
    console.log(makeString());
}

const makeString = () => {
    return "hello javascript";
}

const paramFunciont1 = (a, b) => {
    console.log(`a + b = ${a + b}`);
}

const paramFunciont2 = (name = "hong") => {
    console.log(`name = ${name}`);
}

const paramFunciont3 = (arr) => {
    console.log(`arr = ${arr}`);
}

JS 예외처리

const exceptionFunction = () => { try { example(); } catch (e) { alert(`error log : ${e}`); console.log(`error log : ${e}`); } console.log("hello wolrd"); }

객체, 배열 내 함수 호출


const arrFunction = () => {
    const arr = [1, 2, () => { console.log("hello"); }];
    arr[2]();
}

const createPerson = (name, email, age) => {
    return {
        name,
        email,
        age,
        printPerson: () => { return `이름은 ${name}, 이메일은 ${email}, 나이는 ${age}` }
    };
}

const objFunction = () => {
    const p1 = createPerson("hong", "hong@naver.com", 30);
    console.log(p1);
    console.log(p1.printPerson());
}

window 객체 함수(내장함수)

  • 알림창 출력: alert();
  • 새로고침 실행: window.location.reload();
  • 페이지 이동: window.location.href = "이동경로URL";

이벤트리스너(event listner) 함수 활용

사용자가 html 화면 내에서 특정행위(event)를 했을 때 자동 실행되는 함수

  • window.addEventListener('scroll', () => console.log("hello"));
  • element.addEventListener('click', () => console.log("hello"));

스크롤 이벤트 버튼 클릭 후 스크롤 시 출력 실행

클릭 이벤트 버튼 클릭 후 콘솔버튼 클릭 시 출력 실행