const data = {}
console.log(data.user) // user를 찾을 수 없다는 에러발생.
console.log(data.user) // undefined
console.log(data?.user) // 가능
delete data?.user // 가능
data?.user = 'kim_nuvi' // 에러 undefined = 'kim_nuvi' 상황이 되기 때문.
data.createUser?.() // data가 존재하고 매소드가 존재하면 매소드 실행 아니면 undefined
data?.createUser() // data가 존재하면 함수 호출 아니면 undefined
data.userList?.[10000] // 배열이 존재하면 값반환 아니면 undefined
console.log(1808/6153) //output: 0.29384040305542014
console.log(parseFloat((1808/6153).toFixed(2))) //output : 0.29
console.log(parseFloat((1808/6153).toFixed(2))*100) //output: 28.999999999999996
console.log(Math.round((1808/6153)*100)) //output: 29
function marry(man, woman) {
woman.husband = man;
man.wife = woman;
return {
father: man,
mother: woman
}
}
let family = marry({
name: "John"
}, {
name: "Ann"
});
delete family.father;
delete family.mother.husband;
family = null;
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
console.log( counter() );
console.log( counter() );
console.log( counter() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
console.log( counter() );
console.log( counter() );
console.log( counter() );
console.log( counter2() );
counter = null
counter = makeCounter();
console.log( counter() );
let name = "John";
function sayHi() {
console.log("Hi, " + name);
}
name = "Pete";
sayHi(); // what will it show: "John" or "Pete"?
function makeWorker() {
let name = "Pete";
return function() {
console.log(name);
};
}
let name = "John";
// create a function
let work = makeWorker();
// call it
work(); // what will it show?
function add(x, y) {
return x + y
}
// 2. 함수 표현식 (함수 이름 생략 가능)
var add = function(x, y) {
return x + y
}
// 3. Function 생성자 함수
var add = new Function('x', 'y', 'return x+ y')
// 4. 화살표 함수 (함수의 이름 생략 가능)
var add = (x, y) => x + y
function makeCounter() {
let count = 0;
let returnCounter = new Function('count++')
return returnCounter
};
let counter = makeCounter();
console.log( counter()() );
const data = {}
console.log(data.user) // user를 찾을 수 없다는 에러발생.
console.log(data.user) // undefined
console.log(data?.user) // 가능
delete data?.user // 가능
data?.user = 'kim_nuvi' // 에러 undefined = 'kim_nuvi' 상황이 되기 때문.
data.createUser?.() // data가 존재하고 매소드가 존재하면 매소드 실행 아니면 undefined
data?.createUser() // data가 존재하면 함수 호출 아니면 undefined
data.userList?.[10000] // 배열이 존재하면 값반환 아니면 undefined
console.log(1808/6153) //output: 0.29384040305542014
console.log(parseFloat((1808/6153).toFixed(2))) //output : 0.29
console.log(parseFloat((1808/6153).toFixed(2))*100) //output: 28.999999999999996
console.log(Math.round((1808/6153)*100)) //output: 29
function marry(man, woman) {
woman.husband = man;
man.wife = woman;
return {
father: man,
mother: woman
}
}
let family = marry({
name: "John"
}, {
name: "Ann"
});
delete family.father;
delete family.mother.husband;
family = null;
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
console.log( counter() );
console.log( counter() );
console.log( counter() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
console.log( counter() );
console.log( counter() );
console.log( counter() );
console.log( counter2() );
counter = null
counter = makeCounter();
console.log( counter() );
let name = "John";
function sayHi() {
console.log("Hi, " + name);
}
name = "Pete";
sayHi(); // what will it show: "John" or "Pete"?
function makeWorker() {
let name = "Pete";
return function() {
console.log(name);
};
}
let name = "John";
// create a function
let work = makeWorker();
// call it
work(); // what will it show?
function add(x, y) {
return x + y
}
// 2. 함수 표현식 (함수 이름 생략 가능)
var add = function(x, y) {
return x + y
}
// 3. Function 생성자 함수
var add = new Function('x', 'y', 'return x+ y')
// 4. 화살표 함수 (함수의 이름 생략 가능)
var add = (x, y) => x + y
function makeCounter() {
let count = 0;
let returnCounter = new Function('count++')
return returnCounter
};
let counter = makeCounter();
console.log( counter()() );
const data = {}
console.log(data.user) // user를 찾을 수 없다는 에러발생.
console.log(data.user) // undefined
console.log(data?.user) // 가능
delete data?.user // 가능
data?.user = 'kim_nuvi' // 에러 undefined = 'kim_nuvi' 상황이 되기 때문.
data.createUser?.() // data가 존재하고 매소드가 존재하면 매소드 실행 아니면 undefined
data?.createUser() // data가 존재하면 함수 호출 아니면 undefined
data.userList?.[10000] // 배열이 존재하면 값반환 아니면 undefined
console.log(1808/6153) //output: 0.29384040305542014
console.log(parseFloat((1808/6153).toFixed(2))) //output : 0.29
console.log(parseFloat((1808/6153).toFixed(2))*100) //output: 28.999999999999996
console.log(Math.round((1808/6153)*100)) //output: 29
function marry(man, woman) {
woman.husband = man;
man.wife = woman;
return {
father: man,
mother: woman
}
}
let family = marry({
name: "John"
}, {
name: "Ann"
});
delete family.father;
delete family.mother.husband;
family = null;
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
console.log( counter() );
console.log( counter() );
console.log( counter() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
function makeCounter() {
let count = 0;
return function() {
return count++;
};
}
let counter = makeCounter();
let counter2 = makeCounter();
console.log( counter() );
console.log( counter2() );
console.log( counter() );
console.log( counter() );
console.log( counter() );
console.log( counter2() );
counter = null
counter = makeCounter();
console.log( counter() );
let name = "John";
function sayHi() {
console.log("Hi, " + name);
}
name = "Pete";
sayHi(); // what will it show: "John" or "Pete"?
function makeWorker() {
let name = "Pete";
return function() {
console.log(name);
};
}
let name = "John";
// create a function
let work = makeWorker();
// call it
work(); // what will it show?
function add(x, y) {
return x + y
}
// 2. 함수 표현식 (함수 이름 생략 가능)
var add = function(x, y) {
return x + y
}
// 3. Function 생성자 함수
var add = new Function('x', 'y', 'return x+ y')
// 4. 화살표 함수 (함수의 이름 생략 가능)
var add = (x, y) => x + y
function makeCounter() {
let count = 0;
let returnCounter = new Function('count++')
return returnCounter
};
let counter = makeCounter();
console.log( counter()() );
const data = {}
console.log(data.user) // user를 찾을 수 없다는 에러발생.
console.log(data.user) // undefined
console.log(data?.user) // 가능
delete data?.user // 가능
data?.user = 'kim_nuvi' // 에러 undefined = 'kim_nuvi' 상황이 되기 때문.
data.createUser?.() // data가 존재하고 매소드가 존재하면 매소드 실행 아니면 undefined
data?.createUser() // data가 존재하면 함수 호출 아니면 undefined
data.userList?.[10000] // 배열이 존재하면 값반환 아니면 undefined
console.log(1808/6153) //output: 0.29384040305542014
console.log(parseFloat((1808/6153).toFixed(2))) //output : 0.29
console.log(parseFloat((1808/6153).toFixed(2))*100) //output: 28.999999999999996
console.log(Math.round((1808/6153)*100)) //output: 29