Posts

[JavaScript] Object (this), Array

  const superman = {     name : 'clark' ,     age : 33 ,     fly : function (){         console . log ( "Flying" )     } } superman . fly (); "Flying" method: 객체 property로 할당 된 function function 생략가능  const superman = {     name : 'clark' ,     age : 33 ,     fly (){         console . log ( "Flying" )     } } superman . fly (); this  const user = {     name : "Mike" ,     sayHello : function (){         console . log ( `Hello, I'm ${this . name } ` );     } } user . sayHello (); use.name 으로하면 Error 발생 *화살표 함수는 일반함수와 달리 자신만의 This를 가지지 않음. (외부에서 값을 가져옴) let boy = {     name : "Mike" ,     sayHello : () => {         console . log ( this );     } } boy . sayHello (); this !=boy   브라우저: window Node js: global let boy = {   ...

[JavaScript] Object

 객체 (Object) const superman = {     name : "clark" ,     age : 33 , } 접근 superman . name superman [ "age" ] . 또는 [] 이용 추가 superman . gender = "male" ; superman [ "haircolor" ] = "brown" ; 삭제 delete superman . haircolor ; 코드 단축 const superman = {     name = name,     age = age,     gender : "male", } 코드를 단축 할 수 있음 const superman = {     name ,     age ,     gender : "male" ; } Property 존재 여부의 확인은 in 연산자를 이용..  const superman = {     name = "clark" ,     age = 33 ,     gender : "male" , } superman . birtyhDay ;   //undefiened 'birthday' in superman ;   // false 'age' in superman ; // true const superman = {     name : "clark" ,     age : 30 , } console . log ( superman . name ) console . log ( superman [ "age" ]) "clark" 30 객체만들기 function makeObject ( name , age ){     return {     ...

[JavaScript] For loop , Function

Image
let fruit = prompt ( "which one you need ?" ) switch ( fruit ){   case "apple" :     console . log ( "1,000" );     break ;   case "Banana" :     console . log ( "500" );         break ;   case "Melon" :     console . log ( "2,000" );         break ;   default :     console . log ( "Sorry, We don't sell that one" ); } prompt 는  그 값의 아래는 전부 불러옴. 예를들어 Banana를 입력했을 깨 500과 그 아래 값들도 모두 불러옴. 때문에 break 를 써줘야함 default는 해당하지 않는 값을 입력했을 때 ..  Function function showError (){   alert ( "Error, Try again" ) } showError (); function sayHello ( name ){   const msg = `Hello, ${ name } ` ;   console . log ( msg ); } sayHello ( 'Mike' ); sayHello ( "Jane" ); "Hello, Mike" "Hello, Jane" function sayHello ( name ){     let msg = `Hello` ;     if ( name ){         msg += ', ' + name ;     }     console...

[JavaScript] Prompt, Alert, Confirm

Image
const name = prompt("Put your name"); prompt can put default  const name = prompt("Put your Date of Birth", "12/25/2002"); alert("welcome, " + name ); confirm(Are you an adult?)   ------- True or False Let's say Eng: 90, Math: 60  4530 However, we got odd number. because prompt input the value as "string" so the numbers we put was recognized as "string".    Boolean Number(null) // 0 Number(undefined) // Nan Number(0) // False Number("0") // True Number("") // False Number(" ") // True  const num 2**3; console.log(num);    // 8                                                                     True ===   :  asking the type as well                       ...

[JavaScript] ES6

ECMAScript, or ES, is a standardized version of JavaScript. Because all major browsers follow this specification, the terms ECMAScript and JavaScript are interchangeable. Most of the JavaScript you've learned up to this point was in ES5 (ECMAScript 5), which was finalized in 2009. While you can still write programs in ES5, JavaScript is constantly evolving, and new features are released every year. ES6, released in 2015, added many powerful new features to the language. In this course, you'll learn these new features, including arrow functions, destructuring, classes, promises, and modules. 1 . Compare Scopes of the var and let Keywords If you are unfamiliar with let, check out this challenge. When you declare a variable with the var keyword, it is declared globally, or locally if declared inside a function. The let keyword behaves similarly, but with some extra features. When you declare a variable with the let keyword inside a block, statement, or expression, its scope is lim...