[TIL] more about JS

Soo·2022년 11월 10일
1
post-thumbnail
post-custom-banner

Few things I learned today were listed below:

  • Array
    An array is a special variable, which can hold more than one value:
    > const str = 'Hello'

str[2]
l
str[str.length -1]
o

  • Creating arrays
    [element, element, ..., element]
> const array = [273, 'String', true, function () { }, {}, [273,103]]

undifined

> array
(6) [273, "String", true, f, {...}, Array(2)

// (6) = number of elements 
   [273, "String", true, f, {...}, Array(2) = elements
  • Index
    order of elements:

    array[index]

example (1)

> const numbers =[273, 52, 103, 32]
undefined

> numbers[0]
273
> numbers[1]
52

> numbers [1 + 1]
103
> numbers [1 * 3]
32

In this example (1), I did not get that why > numbers [1 + 1] is 103, because I thought it could be 104 which is '52+52'.

However, the problem was not about the 52. Ok, Let's do the number 1+1 first. The result will be definitely 2. Next, you go back to the index and look up numbers[2]. Now you can see that [1+1] is 103 which is numbers[2] then.

profile
Soogineer's Devlog
post-custom-banner

0개의 댓글