본문 바로가기
JavaScript/Youtube

JavaScript/freeCodeCamp - Full Course for Beginners 00:00~59:30

by SKim입니다 2020. 6. 14.

youtu.be/PkZNo7MFNFg

 

 

 

인터넷 JS playground - freeCodeCamp 사이트, Codepen.io, Scrimba.com

 

 

 

 

 

변수의 선언 방법 1. var

be able to be used throughout your whole program.

 

변수의 선언 방법 2. let

only be used within the scope of where you declare that.

 

변수의 선언 방법 3. const

절대 변할 수 없다.

 

 

 

변수를 declare(선언)하는 것과 assign(할당)하는 것은 차이가 있다.

 

첫째줄은 declare하는 방법이다.

둘째줄은 declare과 assign을 동시에 하는 방법이다.

 

 

Initializing a variable to an initial value at the same time it's declared.

uninitialized = the value is undifined

 

 

JS에서 변수 이름과 함수 이름은 case-sensitive하다.

= 대/소문자가 영향을 끼친다.

알파벳이 같아도 대소문다가 다르면 다르다.

 

이런 식으로 쓰기

 

 

 

 

 

float

 

 

 

 

remainder: 나머지

짝수인지 홀수인지 determind하기 위해 주로 사용한다.

 

 

 

 

 

single quotation / double quotation marks / backticks

 

다른 방법도 있다.

" 대신 '로 감싸기

backtick(`)으로 감싸면 "와 '를 모두 사용할 수 있다.

 

 

 

 

 

bracket notation is a way to get a character at a specific index within a string.

 

Strings are immutable meaning they cannot be altered once created.
This does not mean that they cannot be changed,

just that the individual characters of a string literal cannot be changed.

 

→ 에러

 

→ 바뀐다.

 

 

 

Mad Lips 게임

 

[ , ]

 

when one of the elements in an array is another array

that's called a nested array

or a multi-dimensional array.

 

 

맨 뒤에 데이터 추가

 

() 붙어 있으니까 함수다. 맨 뒤의 데이터 제거.

 

pop이랑 비슷한데 첫 번째 데이터 제거.

 

push랑 비슷한데 데이터를 맨 처음에 추가한다.

nested array의 다른 예

 

, 12]

 

scope refers to the visibility of variables.

variables which are defined outside of a function block have global scope.

global scope means they can be seen everywhere in your JavaScript code.

 

myGlobal이라는 변수는 함수 밖에서 declare되었으므로,

이 변수를 fun2라는 함수를 포함한, 코드 전체에서 볼 수 있다.

fun2라는 함수에서 변수 myGlobal을 reference했다.

 

fun2()의 첫 번째 if문의 조건은

'만약 myGlobal 변수의 type이 undefined가 아니라면 = define되었다면'이다.

만약 myGlobal 변수가 define되었다면 true가 된다.

myGlobal 변수는 global scope이므로 10으로 define되었다.

 

두 번째 if문의 조건은 변수 oopsGlobal을 대상으로 하고 있다.

 

fun1()에 oopsGlobal 변수를 정의해보겠다.

var를 사용하지 않고도 변수를 정의할 수 있다.

 

var를 사용하면 oppsGlobal = 5;가 함수 안에 존재하기 때문에

→ it will be scoped to that function

→ 다른 함수에서 보지 못한다.

 

그러나 이 예시처럼 var를 사용하지 않으면,

자동으로 global 변수가 된다.

= 이 프로그램의 (fun2()함수 안을 포함하여) 어느 곳에서나 접근할 수 있다.

 

∴ 만약 var 키워드를 사용하면,

oopsGlobal은 undefined 된다.

 

그러나 우리가 var 키워드를 사용하지 않았기 때문에,

oppsGlobal은 5이다.

댓글