기본 자바스크립트 정리

Jeon곰탱·2021년 11월 23일
0

Nomadcoder

목록 보기
1/5
post-thumbnail

웹 = 자바스크립트


  • 브라우저 엔진은 자바스크립트 내장이 되어있다
  • 즉 JS하나로 모든 것을 커버한다.
  • 그래픽, 머신러닝 등등 가능하다.

Basic DataType


  • nubmer
  • text
1
2
3.14
hello //에러
"hello"

Variables

  • const를 기본으로 한다.(=업데이트는 종종하기 )
  • undefined=값이 정의되지 않음
  • null=값이 없음

Arrays

const mon = "mon";
const tue = "tue";
const wed = "wed";
const thu = "thu";
const fri = "fri";
const sat = "sat";
const sun = "sun";
const week = [mon,tue,wed,thu,fri,sat,sun];
[ ] = Array;

// Get a item from Array
console.log(week[4]);

// Add one more to the array
week.push("hi")

Object

Object는 컨테이너 이다.

const playerName = "joshua";
const playerPoints = 1455;
const playerHandsome = false;
const playerFat = "little bit";

const player = ["joshua",1455,false,"little bit"];

//curly brace
const player = {
    name : "joshua",
    point : 10,
    fat : true,
    handsome : "little bit",
}
player.lastname = "david";

Function

const player = {
    name : `happy`,
    sayHi : function (){
        console.log("hey!")
    },
};

Recap

function x() {}
x // nothing
x(); //execution

//calculator
const calculator = {
    add : function (x,y) {console.log(x+y);},
    minus : function (x,y) {console.log(x-y);},
    multi : function (x,y) {console.log(x*y);},
    divide : function (x,y) {console.log(x/y);},
}

Return

const calculator = {
    add : function (x,y) {return (x+y);},
    minus : function (x,y) {return (x-y);},
    multi : function (x,y) {return (x*y);},
    divide : function (x,y) {return (x/y);},
}

const result = calculator.add(5,7);

Conditional

const age = parseInt(prompt("몇 살이세요?"))

if(isNaN(age)){
    console.log("에바야")
} else if(age < 20){
    console.log("어리누")
} else{
    console.log("늙었누")
}
profile
Atomic habits make me

0개의 댓글