<vanilla JS_#2.1 Your first JS Function

insum·2019년 8월 26일
0

Vanilla JS

목록 보기
4/6
const janeInfo = {
    name: "jane",
     age: 23,
     gender: "anything",
     isItHuman: true,
     favFood: ["coffee", "만두", "라면"],
     favSong: [
        {shinee:"I want you",
        isItGood: true
        },
        {boa: "only one",
        isItBad: false 
        }
    ]
}

janeInfo가 Object인 것 처럼, console은 Object다.
.log(key)는 .favSong(key)처럼 자바스크립트 안에 있는 것이다.

console.log //이 경우 .log는 함수이고 Object이기도 하다.
(janeInfo.favSong[0].isItGood)
//--> true

만약, console객체를 console.log로 찍어 보면 어떨까?

console.log(console)


브라우저가 가지고 있는 자바스크립트를 객체안에 넣을수도 있다.
console.log, alert 등 많은 이런 함수들을
built-in function(내장함수)이라고 한다.

function is.. function
어떤것의 기능
한 코드 조각으로 내가 원하는 만큼 쓸 수 있는 코드

이름을 받아와서 무슨 이름이든
hello를 붙여주는 함수를 만들고 싶어!


function sayHello(who, age)//parameter 
{
	console.log("Hello " + who, "you have",
	age, "years of age"
	);
}

sayHello("jay", 22); //argument  
//--> Hello jay you have 22 years of age

파라미터 값을 추가해볼까요?

/
+(플러스)연산자만 되는건 줄 알았는데
콤마 찍어도 되는구나 하고 오늘 알았다.
/

//console.log 함수는 argument를 무한하게 가질 수 있다.

profile
Hello!

0개의 댓글