본문 바로가기
ETC/정보처리기사

[JS] 자바스크립트 기초 학습 (변수, array, objects, function,조건문)

by sssinga 2022. 10. 26.

1 -> integer

1.1 -> float

"hi" -> string

 

변수 선언

const a = 1;

const myName = "ss";

-> JS에서는 변수명을 첫단어는 소문자 다음 단어부터는 대문자를 쓰는 형식으로 가져간다 (camelCase)

const 값을 업데이트 하지 않는 경우 (대부분) 재선언x 재할당x
let 값을 업데이트해서 쓸 일이 있는 경우 (가끔) 재선언x 재할당o
var 구버전이야 쓰지마 재선언o 재할당o

 

 

Booleans

true O
false X
null 빈 값이 있음
undefined 값이 없음

 

 

array

const toStudy = ["ABAP", "JAVA", "PYTHON"]

toStudy.push("HTML");

 

 

objects

const player = {
	name: "ss",
    points: 10,
};

player.points = palyer.points + 5;
player.tier = "Master";   // player 객체에 tier: "Master" 추가됨

 

 

function

- 반복되는 코드 캡슐화

function sayHello(name, age) {
	console.log("name: " + name + "age: " + age);
}

sayHello("ss", 20);
sayHello("nn", 30);
const plyaer = {
	name: "ss",
    sayHello: function (otherName) {
    	console.log("name: " + otherName);
    },
};

player.sayHello("nn");

 

 

조건문

console.log(typeof number);		// 타입 확인
parseInt()		// string->number

if (conditionA) {
	// conditionA가 true일 때 실행
} else if (conditionB) {
	// conditionA가 false이고 conditionB가 true일 때 실행
} else {
	// conidtionA와 conditionB 모두 false일 때 실행
}

댓글