본문 바로가기
프로그래밍

2023-05-08 javascript

by AandBB 2023. 5. 8.

<before>

let before=1, after=1, sum=0;

for (let i=1;i<=50;i++){
  if(i<=2){
    console.log(1);
  }else{
    sum=before+after;
    console.log(sum);
    before=after;
    after=sum;
  }
}

<after>

let before=0, after=1 , temp=0;

for (let i=1;i<=50;i++){
  console.log(after);
  temp=before;
  before=after;
  after=temp+after;
}

 


let codeit = {
key1 : value1,
key2 : value2,
...
keyn : valuen,
}

One pair of key : value is called property. We also call key as property name and value as property value.

We have to seperate each property by using ,(comma) not ;

Unlike property value, the type of property name is only string.

We can approach to value of property by using either codeit.key1 or codeit['key1']

 

We use delete keyword to delete property in object.

We use in keyword to check if there is a property in object or not. Like this 'key1' in codeit.

 

In case of integer(whole number) property names, object aligns them first from smallest number to bigger number.

And then object alligns other types of property names by the order that are added.

We have to avoid using integer(whole number) property names.


We create date object like this.

let myDate = new date();

The time when we created date object.

let myDate = new date('2023-05-08');

Specific date we chose. We have to pass string type of date for parameter!

let myDate = new date('2023-05-08T15:51:00');

Specific time as well.

let myDate = new date(2023,5,8,15,55,30,ms);

We can also create date object like this. Year and month parameters are neccessary. The month parameter start with 0.

 

getTime method shows how many ms(millisecond) has passed from standard time(1970-01-01 00:00:00 UTC), and we call it 'timestamp'. We use getTime method to get time difference between now and specific time.

getDay method returns 0~6. 0 means Monday and so on.

let myDate = new Date();

console.log(Date.now() === myDate.getTime()); // true

Date.now method returns timestamp when the method was called. If we just want to get current time value, it is desirable to use Date.now(), instead of first create new object and then call getTime method.

'프로그래밍' 카테고리의 다른 글

2023-05-16 javascript_array  (0) 2023.05.16
2023-05-13 javascript  (0) 2023.05.13
2023-05-11 javascript  (0) 2023.05.11
2023-05-07 javascript  (0) 2023.05.07
2021/12/16 C언어 메모(백준)  (0) 2021.12.16