본문 바로가기
TIL/TIL

createElement, instance in JS

by koreashowme 2020. 2. 18.

const image = new Image();

 

This creates a new Image Instance in JavaScript.

It is functionally equivalent to document.createElement('img')

=> const image = document.createElement("img")

 

const IMG_NUMBER = 4 

const number = Math.floor(Math.random() * IMG_NUMBER);

Math. random ( ) => 0부터 시작한다. 

 

image.src = `images/${imgNumber + 1}.jpeg`;  => 0부터 시작해서 (0, 1, 2, 3) + 1 해서 데이터를 불러온다.

'TIL > TIL' 카테고리의 다른 글

Event Loop & heap & stack  (0) 2020.02.23
비동기, 서버요청, this  (0) 2020.02.23
event.target VS event.currentTarget  (0) 2020.02.17
Delete local storage data  (0) 2020.02.17
새로운 데이터 값 id 주기 JSON, array.length + 1  (0) 2020.02.16

comment