본문 바로가기

JavaScript25

Javascript Run Environment 자바스크립트는 싱글 스레드이지만, 브라우 저상에서 동시에 많은 일을 하는듯해 보입니다. 이번에는 이러한 작동과정 원리에 대해 알아보았습니다. 이 작동은 4가지를 중심으로 이루어졌습니다. 1. javascript 엔진 2. web api 3. callback queue(task queue) 4. event loop HEAP과 STACK은 자바스크립트 엔진을 의미합니다. HEAP에는 객체, 변수 같은 것들이 들어가고 STACK에는 콜백함수가 들어갑니다. 예시 예시를 통해 JAVASCRIPT RUN ENVIRONMENT를 설명해보겠습니다. default : (EVENT LOOP가 엔진, Render, Queue를 계속 순회함) 1. 이벤트 발생(WEB API) => 2. TASK QUEUE에 코드 블록 생성 .. 2022. 2. 11.
getBoundingClientRect() Vs css 좌표 getBoundingClientRect()는 엘리먼트의 좌표값을 알 수 있는 api입니다. 그런데, 이 좌표값이 css와 혼동이 있어서 정리 해 보았습니다. getBoundingClientRect() css ex) (getBoundingClientRect()) right:1240px; bottom:569 (css) position: fixed right:40px; bottom:40px; 두 좌표가 같은 element를 의미하고 있습니다. (화면크기에 따라 위에 해당 하는 값 다를 수 있음) 결론 getBoundingClientRect()를 이용할 때는 right, bottom의 기준이 왼쪽 상단이지만, css에서 right, bottom을 측정할 때는 element를 기준으로 값을 지정했습니다. 2022. 2. 1.
[LeetCode] Valid Parentheses (javascript) 문제 Given a string s containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. 문제[번역] '(', ')', '{', '}', '[' ,']'를 포함한 문자열이 주어집니다. 문자열이 유효한지 평가하세요. 1. 열린괄호는 같은괄호로 닫혀야함. 2. 열린 괄호는 순서대로 닫혀야함. Example 1 Input: s = "(.. 2021. 12. 27.
[LeetCode] Roman to Integer (Javascript) 문제 Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M. Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1000 For example, 2 is written as II in Roman numeral, just two one's added together. 12 is written as XII, which is simply X + II. The number 27 is written as XXVII, which is XX + V + II. Roman numerals are usually written largest to smallest from left to right. How.. 2021. 12. 17.
[LeetCode] palindrome (javascript) 문제 Given an integer x, return true if x is palindrome integer. An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not. 문제[번역] 정수 x가 주어집니다. palindrome 정수라면 true를 리턴합니다. palindrome 정수란, 뒤로 읽어도 같은 수를 의미합니다. 예를 들면 121은 palindrome이며, 123은 아닙니다. Example 1 Input: x = 121 Output: true Example 2 Input: x = -121 Output: false Explanation: Fro.. 2021. 12. 16.
[자바스크립트] Array.some() Array.some()이란 메서드중 하나로, 주어진 배열안에서 하나라도 주어진 조건을 통과하는지 테스트하는 함수 입니다. 예시 코드1 const arr =[1,1,3,1,5]; const even = (element) => element%2 === 0; console.log(arr.some(even)); true 예시 코드2 const arr =[1,2,3,1,5]; const even = (element) => element%2 === 0; console.log(arr.some(even)); true 예시 코드3 console.log([1,2,3,4,5].some((element) => { if(element %2 ===0) console.log("even"); else console.log("odd".. 2021. 12. 14.
반응형