본문 바로가기

Dev/JavaScript17

[JavaScript] Conditionals const age = parseInt(prompt("How old are you?")); // 사용자에게 값을 받는 창을 띄움, 오래된 기술 잘 안씀~ console.log(age); //string -> int 바꾸기 console.log(parseInt(age)); // 숫자가 아닌 것을 인지할 수 있음 - 숫자가 아니면 NaN (Not a Number) //value의 type 보기 console.log(typeof age); // 기본 타입이 string console.log(isNaN(age)); // 숫자가 아니면 true, 숫자면 false //Conditionals if (isNaN(age)){ // condition === true console.log("Please write a num.. 2022. 4. 27.
[JavaScript] Return // return const age = 96; function calculateKrAge(ageOfForeigner){ return ageOfForeigner + 2; } // 결과를 외부에서 받을 수 있다. const krAge = calculateKrAge(age); console.log(krAge); const calculator = { add: function (a, b){ return a + b; }, minus: function(a, b){ return a - b }, div: function (a, b){ return a / b }, mul: function (a, b){ return a * b }, powerof: function (a, b){ return a ** b; } }; // 상호.. 2022. 4. 27.
[JavaScript] Functions function sayHello(nameOfPerson, age) { console.log("Hello! my name is "+ nameOfPerson + " and I'm "+ age); } sayHello("nico", 10); sayHello("dal", 23); sayHello("lynn", 15); function plus(a, b) { //매개변수는 메서드 내에서만 존재 console.log(a + b); } function divide(a, b) { console.log(a / b); } plus(8, 60); divide(98, 20); const player = { name : "nico", sayHello : function(otherPersonName) {// function에서 정.. 2022. 4. 26.
[JavaScript] 데이터 구조 const mon = "mon"; const tue = "tue"; const wed = "wed"; const thu = "thu"; const fri = "fri"; const sat = "sat"; const sun = "sun"; // array 배열 const daysOfWeek = [mon, tue, wed, thu, fri, sat, sun]; const nonsense = [1, 2, "hello", false, null, true, undefined]; // 대괄호로 둘러싸여 쉼표로 분리 console.log(daysOfWeek, nonsense); const daysOfWeek = ["mon", "tue", "wed", "thu", "fri", "sat"]; // Get Item fro.. 2022. 4. 26.