JavaScript & TypeScript
-
7. Array, APIJavaScript & TypeScript 2020. 11. 14. 14:17
Array 1. Declaration const arr1 = new Array(); const arr2 = [1, 2]; 2. Index position const fruits = ['apple', 'banana']; console.log(fruits); // 'apple', 'banana' console.log(fruits.length); // 2 console.log(fruits[0]); // 'apple' console.log(fruits[1]); // 'banana' console.log(fruits[2]); // undefined console.log(fruits[fruits.length - 1]); // 'banana' 3. Looping over an array print all fruits..
-
6. what is objectJavaScript & TypeScript 2020. 11. 14. 12:31
Objects one of the JavaScript's data types a collection of related data and/or functionality Nearly all objects in JavaScript are instances Object object = { key : value }; 1. Literals and properties const obj1 = {}; // 'object literal' syntax const obj2 = new Object(); // 'object constructor' syntax function print(person) { console.log(person.name); console.log(person.age); } const ellie = {nam..
-
5. class vs objectJavaScript & TypeScript 2020. 11. 14. 11:06
class template declare once no data in introduced in ES6 syntactical sugar over prototype-based inheritance 1. class declarations class Person { // constructor constructor (name, age) { // fields this.name = name; this.age = age; } // methods speak() { console.log(`${this.name}: hello! `); } } const ellie = new Person('ellie', 20); console.log(ellie.name); // ellie console.log(ellie.age); // 20 ..
-
4. Arrow FunctionJavaScript & TypeScript 2020. 11. 13. 18:04
Function fundamental building block in the program subprogram can be used multiple times performs a task or calculates a value 1. Function declaration function name(param1, param2) { body ... return; } one function === one thing naming: doSomething, command, verb e.g.createCardAndPoint ->. createCard, createPoint function is object in JS function printHello() { console.log('Hello'); } printHello..
-
3. operator, if, for loopJavaScript & TypeScript 2020. 11. 13. 17:40
1. String concatenation console.log('my' + ' cat'); // my cat console.log('1' + 2); // 12 console.log(`string literals: 1 + 2 = ${1 + 2}`); // 1 + 2 = 3 2. Numeric operators console.log(1 + 1); // add : 2 console.log(1 - 1); // substract : 0 console.log(1 / 1); // divide : 1 console.log(1 * 1); // multiply : 1 console.log(5 % 2); // remainder : 1 console.log(2 ** 3); // exponentiation : 8 3. Inc..
-
2. data types, let vs var, hoistingJavaScript & TypeScript 2020. 11. 13. 17:21
1. let vs var, hoisting Variable, rw(read/write) let (added in ES6) scope global scope block scope Var var (don't ever ues this) var hoisting (move declaration from bottom to top) has no block scope block scope ignore Constant, r (read only) favor immutable data type always for a few reasons security thread safety reduce human mistakes 2. data types Variable types primitive, single item number s..
-
1. script async vs deferJavaScript & TypeScript 2020. 11. 13. 16:56
1. async vs defer - head - js 파일 사이즈가 크고 인터넷이 느리면 사용자가 웹사이트를 보는데 시간이 많이걸린다. - body - js에 의존적이라면 js가 실행될때까지 기다려야한다. - head + async - js에서 html 부분을 다루려고 할때 parsing 되어있지 않으면 문제가 생기고 시간이 좀 걸린다. - head + async - js가 순서에 의존적이라면 문제가 될 수 있음 - head + defer - 가장 좋은 옵션 - use strict Whole-script strict mode syntax JavaScript is very flexible flexible == dangerous added ECMAScript 5 'use strict' ※출처 www.yout..