반응형
더하기 연산자( +)와 숫자 생성자( Number())는 문자열을 숫자로 변환하는 데 도움이 됩니다.
문자열을 단항 숫자로 변환하려면 문자열 앞에 더하기 기호를 추가하기만 하면 됩니다. 그리고 숫자 생성자를 사용하여 이를 수행하려면 숫자를Number()
const myNum = '5';
convertNum1 = +myNum;
convertNum2 = Number(myNum);
console.log(convertNum1, typeof convertNum1); // 5 'number'
console.log(convertNum2, typeof convertNum2); // 5 'number'
팁 4: 키워드를 사용하여 모든 변수를 선언할 필요는 없습니다.
여러 개의 변수가 나란히 있는 경우 첫 번째 변수 다음에 모든 변수를 선언하기 위해 const, let또는 사용을 피할 수 있다는 것을 알고 계셨습니까?var
유일한 주의 사항은 키워드 없이 변수를 선언하는 경우 세미콜론 ,대신 쉼표( )로 구분해야 한다는 것입니다.
이거 야:
// declare multiple variables at once.
let x, y, z;
x = 1;
y = 2;
z = 3;
console.log(x, y, z); // 1, 2, 3
// declare other variables after the first one without the keyword.
const a = 'Hello',
b = 'How are you today?',
c = 'Are you coding today?';
console.log(a); // Hello
console.log(b); // How are you today?
console.log(c); // Are you coding today?
위의 내용은 다음과 같습니다.
let x;
let y;
let z;
x = 1;
y = 2;
z = 3;
console.log(x, y, z); // 1, 2, 3
// declare other variables after the first one without the keyword.
const a = 'Hello';
const b = 'How are you today?';
const c = 'Are you coding today?';
console.log(a); // Hello
console.log(b); // How are you today?
console.log(c); // Are you coding today?
반응형