Skip to content

Instantly share code, notes, and snippets.

@tong9433
Last active July 11, 2017 00:08
Show Gist options
  • Save tong9433/0975e7ddf6aa60b2826034eb17c39b63 to your computer and use it in GitHub Desktop.
Save tong9433/0975e7ddf6aa60b2826034eb17c39b63 to your computer and use it in GitHub Desktop.
7/10 과제

!! 의미

boolean으로 형 변환. 0을 false로, 1을 true로.

ex1)

let a = 0;
console.log(a);   // 0
console.log(!a);  // true
console.log(!!a); // false
 
let b = null;
console.log(b);   // null
console.log(!b);  // true
console.log(!!b); // false
 
let c = undefined;
console.log(c);   // undefined
console.log(!c);  // true
console.log(!!c); // false

ex2)

var a = 1;
var result = "I'm a result";
 
if(a){
    console.log(result); // " I'm a result " 출력
    console.log(!result); // " false " 출력
    console.log(!!result); // " true" 출력
}

JavaSript 유래

자바라는 단어가 앞에 들어가 있지만 기술적으로는 자바와 전혀 상관 없다. 자바스크립트를 만든 인물은 넷스케이프에 일했던 브랜든 아이크이며 넷스케이프 설립자였던 마크 앤드리슨의 조언을 받아 ‘모카’라는 이름을 지어줬다고 한다. 모카는 1995년 12월 이름은 ‘라이브 스크립트’라는 이름으로 바뀌었는데, 당시 자바가 큰 인기를 끌자 마케팅 효과를 노려 이름을 자바스크립트로 이름을 변경했다.

map, filter 구현

//map
Array.prototype.newmap = function(func){ 
	var new_arr = [];
  for(let i = 0; i < this.length; i++){
		new_arr.push(func(this[i],i,this));
	}
	return new_arr;
}

//filter
Array.prototype.newfilter = function(func){
	var new_arr = [];
  for(let i = 0;i < this.length; i++){
		if(func(this[i],i,this)==true) new_arr.push(this[i]);
	}
    return new_arr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment