본문 바로가기

Programing/JavaScript

(40)
[JavaScript] 최댓값/최솟값 구하기 Math.max() MDN문서 1 2 3 4 5 6 7 8 9 10 11 console.log(Math.max(1, 3, 2)); // expected output: 3 console.log(Math.max(-1, -3, -2)); // expected output: -1 var array1 = [1, 3, 2]; console.log(Math.max(...array1)); // expected output: 3 Colored by Color Scripter cs Math.min() MDN문서 1 2 3 4 5 6 7 8 9 10 11 console.log(Math.min(2, 3, 1)); // expected output: 1 console.log(Math.min(-2, -3, -1)); // exp..
[JavaScript] 생성자와 new // + this 조금 // 객체 출처 : 생활코딩 생성자와 new 객체 객체란 서로 연관된 변수와 함수를 그룹핑한 그릇이라고 할 수 있다. 객체안에 담겨있는 변수는 프로퍼티(property) 객체안의 프로퍼티(속성)안에 담겨있는 함수를 메소드(method)라한다 객체를 만들어보자. 1 2 3 4 5 6 7 var person = { 'name' : 'egoing', 'introduce' : function(){ return 'My name is '+this.name; } } document.write(person.introduce()); cs 여기서 프로퍼티는 name, introduce 메소드는 introduce안에 있는 function() 이다. 만약 다른 사람의 이름을 담을 객체가 필요하다면 객체의 정의를 반복해야 할 것이다. 객..
Array.prototype.unshift() // 배열의 맨앞에 요소추가 Array.prototype.unshift() 출처 unshift() 메서드는 새로운 요소를 배열의 맨 앞쪽에 추가하고, 새로운 길이를 반환합니다. 1 2 3 4 5 6 7 8 var array1 = [1, 2, 3]; console.log(array1.unshift(4, 5)); // expected output: 5 console.log(array1); // expected output: Array [4, 5, 1, 2, 3] Colored by Color Scripter cs return 메서드를 호출한 배열의 새로운 length 속성. 예제 1 2 3 4 5 6 7 8 9 10 var arr = [1, 2]; arr.unshift(0); // result of call is 3, the new a..
typeof, Number.isInteger(), isFinite(), isNaN() // 데이터 유형찾기 typeof 출처 유형이 뭔지 알려줌 1 2 3 4 5 6 7 8 9 10 11 12 console.log(typeof 42); // expected output: "number" console.log(typeof 'blubber'); // expected output: "string" console.log(typeof true); // expected output: "boolean" console.log(typeof declaredButUndefinedVariable); // expected output: "undefined"; Colored by Color Scripter cs Number.isInteger() 출처 정수인지 여부를 판단 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 fu..
Number 출처 : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number설명 섹션Number객체 의 기본 용도는 다음 과 같습니다.인수를 숫자로 변환 할 수 없으면 리턴합니다 NaN.생성자가 아닌 컨텍스트에서 (즉, new연산자 없이 ) Number형식 변환을 수행하는 데 사용할 수 있습니다.속성 섹션Number.EPSILON두 개의 표현 가능한 숫자 사이의 최소 간격.Number.MAX_SAFE_INTEGERJavaScript ( ) 의 최대 안전 정수입니다 .253 - 1Number.MAX_VALUE가장 큰 양의 표현 가능 숫자.Number.MIN_SAFE_INTEGERJavaScript ( ) 의 최소 ​​..
Array .isArray () // 배열인지 ? Array.isArray () Array.isArray() 방법은 전달 된 값이 있는지 여부를 판단한다 Array . Array.isArray([1, 2, 3]); // true Array.isArray({foo: 123}); // false Array.isArray('foobar'); // false Array.isArray(undefined); // false 구문 섹션 Array.isArray ( value ) 매개 변수 섹션 value 확인할 값입니다. 반환 값 섹션 true 값이 인 경우 Array . 그렇지 않으면 false . 출처 : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/i..
delete operator // 객체에서 삭제 delete operator - 문법 delete expression expression은 속성 레퍼런스여야만 한다. e.g.: delete object.property delete object['property'] 파라미터 object오브젝트의 이름. 또는 오브젝트 표현식.property삭제하고자 하는 속성 리턴 값섹션 non-configurable 속성(역: 속성을 제거할 수 있는지)인 경우를 제외하고는 모든 경우에 관하여 true이다. non-configurable 속성인 경우는 non-strict에서 false를 반환한다. 예외섹션 non-configurable속성인 경우에 strict mode에서 Global_objects/SyntaxError를 낸다. 설명섹션 일반적으로 생각하고 있는것과는 다..
JavaScript : Scope 이해 http://www.nextree.co.kr/p7363/ Hoisting 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 //Hoisting function hoistingExam(){ var value =20; console.log("value="+value); var value =10; console.log("value="+value); } hoistingExam(); //실행결과 /* value= 20 value= 10 */ cs