일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 제이큐그리드
- View
- Model
- ResponseBody
- 자바
- java
- 정보처리기사 합격
- jqGrid
- MariaDB
- HTTP
- 정처기 합격
- 트랜잭션
- Javascript
- HTML
- JQuery
- 정보처리기사 필기
- jqgrid 개념
- Class
- implements
- SQL
- JVM Heap
- spring
- extends
- ModelMap
- Where
- 개발자 이직
- 스프링
- mysql
- ModelAndView
- 어노테이션
- Today
- Total
크리스의 개발일기
자바스크립트(js) 1. data types, let vs var, hoisting 기록 본문
자바스크립트 3. 데이터타입, data types, let vs var, hoisting | 프론트엔드 개발자 입문편 (JavaScript ES5+) by 드림코딩 by 엘리
// 1. Use strict
// added in ES 5
// use this for valina Javascript
'use strict';
// 2. Variable
// let (added in ES6=js)
let globalName = 'global name';
{
let name = 'elile';
console.log(name);
name ='hello';
console.log(name);
}
console.log(name);
console.log(globalName);
// var (Don't ever use this!)
// var hoisting (no matter where it is, move, declaration from bottom to top)
// has no block scope (ignore block scope)
{
age = 4;
var age;
}
console.log(age);
// 3. Constants
// favor immutable data type always for a few reasons:
// - security
// - thread safety
// - reduce human mistakes
const daysInWeek = 7;
const maxNumber = 5;
// in a word : Mutable type(let) / immutable type(const)
// 4. Variable types
// primitive, single item: number, string, boolean, null, undefined, symbol
// object, box container
// function, first-class function
const count = 17; //integer
const size = 17.1; //decimal number
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size}`);
// number - special numeric values: infinity, -infinity, NaN
const infinity = 1 / 0;
const negativeInfinity = -1 / 0;
const nAn = 'not a number' / 2;
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);
// bigInt (fairly new, don't use it yet)
const bigInt = 1234567891234567891234567891234567890; // over (-2**53) ~ 2*53
console.log(`value: ${bigInt}, type: ${typeof bigInt}`);
Number.MAX_SAFE_INTEGER;
// string
const char = 'c';
const brendan = 'brendan';
const greeting = 'hello' + brendan;
console.log(`value: ${greeting}, type: ${typeof greeting}`);
const helloBob = `hi ${brendan}!`; //template literals (string);
console.log(`value: ${helloBob}, type: ${helloBob}`);
//if you use '`', you don't have to '+' instead of it
console.log('value: ' + helloBob + ', type: ' + helloBob);
//boolean
//false: 0, null, undefined, NaN, ''
//true: any other value
const canRead = true;
const test = 3 < 1; //false
console.log(`value: ${test}, type: ${typeof test}`);
console.log(`value: ${canRead}, type: ${typeof canRead}`);
//null
let nothing = null;
console.log(`value: ${nothing}, type: ${typeof nothing}`);
//undefined
let x; //= undefined;
console.log(`value: ${x}, type: ${typeof x}`);
//symbol, create unique identifiers for objects
const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2); //false
//no matter their string values are same, it's different
const gSymbol1 = Symbol.for('id');
const gSymbol2 = Symbol.for('id');
console.log(gSymbol1 === gSymbol2); //true
console.log(`value: ${symbol1.description}, type: ${typeof symbol1}`);
//use description
// object(일상 생활에서 보는 물건과 물체들을 대표할 수 있는 것 ),
// real-life object, data structure
const ellie = { name: 'ellie', age: 20};
ellie.age = 21;
// 5. Dynamic typing: dynamically typed language
let text = 'hello';
console.log(text.charAt(0));
console.log(`value: ${text}, type: ${typeof text}`);
text = 1;
console.log(`value: ${text}, type: ${typeof text}`);
text = '7' + 5;
console.log(`value: ${text}, type: ${typeof text}`);
text = '8' / '2';
console.log(`value: ${text}, type: ${typeof text}`);
source : www.youtube.com/watch?v=OCCpGh4ujb8
'Javascript' 카테고리의 다른 글
호이스팅(hoisting)이란? (0) | 2021.11.05 |
---|---|
[$,JQuery] .attr()과 .prop()의 차이점 (0) | 2021.02.01 |
[Javascript] window.onload()란? (0) | 2020.11.20 |
[Javascript] DOM이란 무엇인가? (0) | 2020.11.06 |
[Javascript] Ajax 개념과 목적, 장단점/ 동기, 비동기 방식 (0) | 2020.11.06 |