Exceptions are used when you want to catch an error and prevent the code from exiting. User inputs increase the chance of errors happening. If the user enters in
This makes an alert box pop out with the string inside.
alert("some word");
This makes the string show in the console. Kind of like a print statement.
console.log();
Commenting is used when you want to write text in code that isn't code.
single line comments
// 주석달 때는 slash 두개로 시작합니다.
multiline comments
/* 두 줄 이상 주석 처리하려면,
잘 막아주세요 */
Use
let
for variables that can be changed andconst
for constant values.
Arrays are same as python, you can add any variable you want no matter the type.
When adding new elemets, you can add elements to specific locations.
cities[5] = "제주도";
Even if the list is empty this is possible. The empty locations will return undefined
The push method will add the new element to the end of the list.
The unshift method will add the new element to the front of the list.
let cities = [];
cities.push("경주", "전주");
cities.unshift("인천");
The pop method will delete the last element of the list and return it.
Date and Time is used alot in Front end developement
var rightNow = new Date();
console.log(rightNow);
--result--
2019-02-18T00:45:06.562Z
Time is typically organized as such
So how do you get parts of the date?
Code
let rightNow = new Date();
let year = rightNow.getFullYear();
let month = rightNow.getMonth()+1;
let date = rightNow.getDate();
let day = rightNow.getDay();
let currentHour = rightNow.getHours();
let currentMin = rightNow.getMinutes();
Result
rightNow : Thu Apr 23 2020 20:48:12 GMT+0900 (Korean Standard Time)
year : 2020
month : 4
date : 23
day : 4
currentHour : 20
currentMin : 48
List of math methods
Math.round();
Math.ceil();
Math.floor();
Math.random();
Same as dictionary