javascript

hyena_lee·2022년 8월 31일
0

JavaScript

목록 보기
2/5
post-thumbnail

🌿 use strict

🌿 variable, rw(read/write) :메모리에 읽고 쓰는게 가능

: 변경 될수 있는 값
🌱 let (added in ES6) : Mutable

let name = "nana";
console.log(name);
name = 'hello';
console.log(name);

🌿 block scope

: 코드를 블록 안에 작성하게 되면 블록 밖에서는 더 이상 블록 안에 있는 애들을 볼 수가 없다.

  • global scope : 블록을 쓰지 않고 파일 안에 다가 바로 정의해서 쓰는 변수를 말함. 필요한 부분에서 쓰기 바람.
  • 호이스팅(hoisting) : 어디 선언했냐 상관 없이 항상 제일 위로 선언을 끌어 올려주는 것을 말함(move declaration from bottom to top)
let globalName = 'global name';

{
let name = "nana";
console.log(name);
name = 'hello';
console.log(name);
}

🌿 Contant, r(read only)

: 한번 할당하면 값이 절대 바뀌지 않는 것을 말함.(const)
favor immutable data type always for a few reasons;

  • security
  • thread safety
  • reduce human mistakes

🌿 Varible types

- primitive, single item: number, string, boolean, 		 null, undefied, symbol
- object, box container
- function, first-class function 

(참고) C data types for number

int main() {
	short a = 12.    // 2  bytes
    int b = 12;      // 4  bytes
    long c = 1234;   // 8  bytes
    float d = 1.2f;  // 4  bytes
    double e = 8.2;  // 16 bytes
    return 0;
}

🌿 const

const count = 19;    //integer
const size = 19.2;   //decimal number
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size}`);

🌿 number

//number - speicla numeric values: infinity, -infinity, NaN
const infinity = 1 / 0;  //양의 무한대를 나나태내는 숫자값
const negativeInfinity = -1 / 0;  //음의 무한대
const nAn = 'not a number' / 2;  //숫자가 아닌 string을 숫자로 나누면 
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);

🌿 bigInt

//bigInt (fairly new, don't use it yet)
_**const bigInt = 12345678901234567890n; **_ //over (-2**53 ~2*53)
console.log(`value: ${bigInt}, type: ${typeof bigInt}`);
Number.Max_SAFE_INTEGER;

🌿 string

🌿 boolean

🌿 null & undefined

🌿 symbol

//symbol
const symbol1 = symbol('id');
const symbol2 = symbol('id');
console.log(symbol1 === symbol2);
// 출력 : false
// 같은 값을 할당해줘도 고유한 식별이기 때문에 비교연산을 해도 다르다고 나옴.
// 동일한 symbol도 만들 수 있다
symbol 을 그냥 출력하면 에러가 난다.
출력할 때는 .description 으로 문자열로 만들어준 뒤 출력해야한다.
console.log(`value: ${symbol.description}`)

🌿 Dynamic typing: dynamically typed language

: 자바나 c 언어는 변수를 선언할 때 어떤 타입인지 결정해서 타입을 같이 선언했던 반면에 자바스크립트는 선언할 때 어떤 타입인지 선언하지 않고 run type 프로그램이 동작할 때 할당된 값에 따라서 타입이 변경 될 수 있다는 것을 말함.

🌿 string concatenation

: + 기호를 이용해서 문자열과 문자열을 합해서 새로운 문자열을 만든다.

-> 줄바꿈 : \n, \tab

🌿 Numeric operators

🌿 ++, -- operators

🌿 = operators

🌿 <= operators

🌿 Logical operators

🌿 Equality operators

🌿 object equality

🌿 equaltiy-puzzler

🌿 If operators

🌿 ? operators


-> if 좀더 간단하게 쓸 수 있는 ? 쓰면 => true 면 왼쪽(true) 실행하고, :(아니면) ' no' 실행해줘.
-> 값을 할당하거나 출력할 때 많이 쓰임.

🌿 Switch operators

🌿 while loop

🌿 do - while loop


-> 블록을 먼저 실행 후 조건이 맞는지 안 맞는지 검사함.

🌿 for loop

🌿 nested loop

🌿 break, continue

🌿 Function

-fundametal building block in the program
-subprogram can be used multiple times
-performs a task or calculates a value

  1. funtion declaration
    function name(param1, param2) { body... return; }
    one function === one thing
    naming: doSomething, command, verb
    e.g. createCarAndPoint -> createCard, createPoint
    function is object in JS

function printHello () {
	console.log('Hello')
}
printHello();  // 쓸모가 별로 없다.
function log(message) {
	console.log(message);
}
log('Hello');
log(1234);

🌿 parameters

🌿 Default Parameters

🌿 Rest Parameters

-> 배열 형태로 전달 (...args)
-> 간단하게 출력하는 방법

🌿 Local scope

🌿 Return

🌿 Early Return

🌿 Function Expression

🌿 Callback hell

🌿 Arrow Function

🌿 IIFE

🌈🌈🌈 회고

다시 시작된 자바스크립트 강의...
배열까지만 들었던 강의 이제서야 다시 처음부터 듣게 되었다. 아직 갈길이 멀지만 내가 맞는 강사를 찾기도 어려웠다. dreamcoding 앨리님 그나마 집중도도 높여주고 머릿속에 제일 많이 남는것같다. 물론 나의 사고력을 높이기 위해 시간을 갖아야 하지만 오늘은 step by step 으로 훑는다고 생각하고 차근차근 살을 붙여가보자.

profile
실수를 두려워 말고 계속 도전 하는 개발자의 여정!

0개의 댓글