본문 바로가기
ONLINE COURSES/JavaScript

FreeCodeCamp_JS_TIL_DAY1

by jono 2021. 6. 23.

1. Escaping quotes

Quotes are not the only characters that can be escaped inside a string. there are two reasons to use escaping characters.
1. to allow you to use characters you may not otherwise be able to type out, such as carriage return.
2. to allow you to represent multiple quotes in a string without javascript misinterpreting what you mean. 

code output
\' single quote
\" double quote
\\ backslash
\n newline
\r carriage return
\t tab
\b word boundary
\f form feed

 


2. Access Multi-Dimensional Arrays With Indexes

One way to think of a multi-dimensional array, is as an array of arrays. When you use brackets to access your array, the first set of brackets to refers to the entries in the outer-most(the first level)array, and each additional pair of brackets refers to the next level of entries inside.

#example

var arr = [
[1,2,3],
[4,5,6],
[7,8,9],
[[10,11,12],13,14]
];

arr[3];        // [[10,11,12],13,14]
arr[3][0];     // [10,11,12]
arr[3][0][1];  // [11]

3. / .push / .pop / .shift / .unshift

 
추가 .unshift() .push()
제거 + 출력 .shift() .pop()

.push() adds the element at the end of the array.
.pop()
 removes the last element from an array and returns that element.

.shift() removes the first element from an array and returns that element
.unshift works exactly like .push(), but instead of adding the element at the end of the array, 
unshift() adds the element at the begining of the array.


4.Function

- parameter : 함수를 만들때 ()안에 넣는 값
- argument : 함수를 호출할때 ()안에 넣는 값

-> Parameters are variables that act as placeholders for the values that are to be input to a fuction when it is called.
When a function is defined, it is typically defined along with one or more parameters.
The actual values that are input(or "passed") into a function when it is called are known as Arguments.


5. scope : 변수에 접근할 수 있는 범위

1) global scope -> function(){}  묶음 에 선언되는 변수의 경우이다. => can be seen everywhere in js code.
2) local scope -> function(){} 묶음 에 선언되는 변수의 경우이다. => only visible within that function.

var globalScope();      // global scope이다.

function myTest(){
  var loc = 'foo';      //function 안에서 선언된 var = local scope
  console.log(loc);
}

myTest();        // foo 출력한다
console.log(loc);  //loc 변수는 myTest함수 안에서만 존재하는 local scope이므로 에러가 반환된다.

=> global scope 와 local scope 변수들은 같은 이름을 사용할 수 있다
=> local scope가 상위가 된다.

 

 

'ONLINE COURSES > JavaScript' 카테고리의 다른 글

FreeCodeCamp_JS_TIL_DAY3  (0) 2021.07.05
FreeCodeCamp_JS_TIL_DAY2  (0) 2021.06.26
DOM-3  (0) 2021.06.15
DOM-2  (0) 2021.06.14
DOM-1  (0) 2021.06.14

댓글