[포스코x코딩온] 풀스택 웹 개발자 부트캠프 2주차 | JavaScript(3)

새벽·2023년 7월 25일

후추수정.. 수업시간에 적어놓고 집에서 정리 ㅇ안하고 여태안올림해헷^-^;;

Javascript 표준 객체

자바 스크립트에 기본적으로 내장되어 있는 객체
String, Number, Array, Date, Math...

Date 객체

javascript에서 시간과 날짜에 대한 정보를 얻기 위해 사용되는 객체

new : 초기화 (기준을 잡기 위함)
new Date() : 현재 시간
new Date(년,월,일,시,분,초,밀리초) : 내가 parameter로 넣은 특정 시간을 가져옴

      let date = new Date();
      console.log(Date.now()); // 기준시간으로부터 지금까지 지난 밀리초

Date 객체 - 함수

  • date.getFullYear() : 연도
  • date.getMonth() : 월
  • date.getDate() : 초기화한 시간의 일
  • date.getDay() : 현재 요일의 index
  • date.getTime() : 내가 기준으로 잡은 시간이 기준 시간으로부터 얼마나 지났는지 msec
  • date.getHours() : 현재 시간 (시)
  • date.getMinutes() : 현재 시간 ( 분)
  • date.getSeconds() : 현재 시간 ( 초)
  // yyyy-mm-dd
  let year = date.getFullYear();
  let month = date.getMonth() + 1;
  let day = date.getDate();
  console.log(`${year}-${month}-${day}`);
  

Math 객체

수학에서 자주 사용하는 상수, 함수를 미리 구현한 javascript 표준 내장 객체

      console.log(Math.PI); // 3.14~
      console.log(Math.E); // 2.71~
      console.log(Math.SQRT2); // 1.414 (루트)

Math 메소드

  • Math.min() : 인수 중에 최솟 값 반환
  • Math.max() : 인수 중에 최댓 값 반환
  • Math.random() : 임의의 부동 소수점 반환
  • Math.round() : 소수점 이하를 반올림한 정수 반환
  • Math.floor() : 소수점 이하를 내림한 정수 반환
  • Math.ceil() : 소수점 이하를 올림한 정수 반환
      console.log(Math.min(45, 2, 0, -1, -5));
	  // -5
      console.log(Math.max(45, 2, 0, -1, -5));
      // 45
      console.log(Math.random());
	  // 랜덤 값
      //   let a = Math.random() * (max - min) + min;
      console.log(Math.random() * 9 + 1);
	  // 
      console.log(Math.round(1.8));
	 // 2
      console.log(Math.floor(1.8));
	 // 1
      console.log(Math.ceil(1.8));
	 // 2

DOM (Document Object Model)s

  • 가지처럼 내려간다고 생각하면 됨

(부모자식 어쩌구모델)

요소선택자

getElementById

getElementsByClassName

getElementsByTagName

getElementsByName (NodeList)


querySelector (NodeList)

querySelectorAll (NodeList)

HTMLCollection vs NodeList
https://merrily-code.tistory.com/212
https://yung-developer.tistory.com/79


요소 다루기

태그의 내부 내용 변경
속성 변경
class 변경


append / pretend : 자식요소로 추가됨

eval : 문자열로 된 연산식을 계산해줌 (쓰면안되는함수)

  • 실습2 테이블 복습 / 프로그래머스
  • jquery 예습

Math 메소드

profile
⋆。˚☁。⋆。˚☾˚。⋆

1개의 댓글

comment-user-thumbnail
2023년 7월 25일

좋은 글 감사합니다. 자주 올게요 :)

답글 달기