본문 바로가기

JavaScript25

JS Primitive type checking 공부 동기? if (typeof "1" === String) { console.log("'1' === String"); } else { console.log("'1' !== String"); } 해당 코드를 보고 true가 나올 것이라 생각했는데, false가 나왔기 때문입니다. 내용 "1"의 타입은 string이니까 당연히 String과 비교하면 참이라고 생각하였지만, console.log(typeof "1"); //string console.log(typeof String); //function 위 코드를 작성해보니 "1"은 원시 타입 string이고, String은 function이었습니다. String()은 String 객체를 만들어주는 함수이니 당연한 결과였습니다. primitive string.. 2022. 3. 10.
[LeetCode] Maximum Subarray (javascript) 문제 Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum. A subarray is a contiguous part of an array. 문제[번역] 정수 숫자열이 주어집니다. 최소 하나의 숫자를 포함한 연속적 최대 합을 구하세요 Example 1 Input: nums = [-2,1,-3,4,-1,2,1,-5,4] Output: 6 Explanation: [4,-1,2,1] has the largest sum = 6. Example 2 Input: nums = [1] Output: 1 Example 3 Input:.. 2022. 3. 7.
JS Falsy값과 null병합 연산자 글 작성 동기 Javascript의 falsy값이 헷갈릴 때가 있어서 이번에 정리해 보았습니다. js의 falsy 값 false 0 -0 null "" undefined NaN 0n(BigInt 사용하면 true) (0n만 false임, 1n 2n 3n...은 true) a = 0n; b = 6 console.log( a || b); // 6 a = 1n; b = 6 console.log( a || b); //1n null 병합 연산자(ES11도입) null 병합 연산자는 ??키워드를 통해 사용할 수 있고 왼쪽 값이 null 또는 undefined일 경우에만 반응 합니다. a = ""; b = 6 console.log( a || b); //6 a = ""; b = 6 console.log( a ?? b).. 2022. 2. 17.
Js 값 할당했을 때 메모리 글 작성 동기 평소에 아무 생각 없이 받아 들였던 JAVASCRIPT의 값의 할당, 재할당 시 메모리 지정 부분이 좀 생소하게 다가와서 이를 정리해보고 싶었습니다. let temp; 이렇게 값을 선언 했을때 let temp=5 값을 할당 했을 때 핵심 변수 선언에다가, 값을 할당하면 같은 메모리를 그대로 사용할줄 알았지만, 메모리를 새로 배정해주었음을 알 수 있었습니다. +재할당하면 메모리 또 재할당함 2022. 2. 16.
[LeetCode] Search Insert Position (javascript) 문제 Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You must write an algorithm with O(log n) runtime complexity. 문제[번역] 정렬된 숫자 와 타겟 숫자가 주어집니다. 타겟을 찾으면 해당 인덱스를 리턴하고, 못찾으면, 순서에 맞는 인덱스를 리턴하세요. O(log n) 알고리즘을 써야합니다. Example 1 Input: nums = [1,3,5,6], target = 5 Output: 2 Ex.. 2022. 2. 15.
Js 함수 vs 메서드 글 작성 동기 javascript를 공부하다보면 함수와 메서드를 구분해서 쓰는 경우를 종종 발견 했습니다. 만날때 마다 비슷하겠거니 하고 넘어갔는데, 이번 기회에 개념 정리를 확실히 하려고 글을 작성 하였습니다. 함수: function 메서드: method 함수(function) function functionName(parameters){ //내용 } 일반적으로 함수란, 특정기능을 수행하며 function 키워드를 사용합니다. 메서드(method) const object = { num: 0, methodName: function () { //내용 } } 메서드란 객체의 프로퍼티중 하나로, 쉽게 말해서 객체 안에 있는 함수를 의미 합니다. 메서드는 또한 객체안의 프로퍼티를 참조하여 조작할 수 있는 동작을.. 2022. 2. 14.
반응형