-
2일차 공부 내용 2JavaScript 2021. 7. 18. 10:35
1. ES6(aka Harmony, aka Java‐Script 2015, aka ECMAScript2015)
ES6 is standard rule of javascript.
ES6 code has to be transcompiled into "safe" ES5 to ensure that it can run anywhere.
There are a lot of new features in ES6.
2. Using Git and terminal or bash
2.1 git install
2.2 create root project repository
Type the following on the project directory
$git init
2.3 create gitignore file
Inevitably, there will be some files you never want to track in version control.
These files can be explicitly excluded in a file called gitignore.
2.4 check current status
$git status
2.5 commit
$git add -A
$git commit -m "<brief description of the changes your just made">
3. Primitive Types
• Number
• String
• Boolean
• Null
• Undefined
• Symbol4. Numbers
No matter what literal format you use (decimal, hexadecimal, exponential,
etc.), the number that gets created is stored in the same format:
a double.5. Strings
Strings in JavaScript represent Unicode text.
In JavaScript, string literals are represented with single quotes, double quotes, or
backticks(Also called a grave accent mark).The backtick was introduced in ES6 to enable template strings.
6. Escaping
const dialog1 = "He looked up and said \"don't do that!\" to Max."; const dialog2 = 'He looked up and said "don\'t do that!" to Max.'; const s = "In JavaScript, use \\ as an escape character in strings.";
7. Template Strings(aka string interpolation)
let currentTemp = 19.5; const message = `The current temperature is ${currentTemp}\u00b0C`;
ES6 introduces string templates.
8. Multiline Strings
const multiline = "line1\n\ line2";
const multiline = `line1 line2`;
const multiline = "line1\n" + "line2\n" + "line3";
const multiline = 'Current temperature:\n' + `\t${currentTemp}\u00b0C\n` + "Don't worry...the heat is on!";
9. Booleans
Booleans are value types that have only two possible values: true and false.
let heating = true; let cooling = false;
10. Symbols
New in ES6 are symbols: a new data type representing unique tokens.
Symbols are created with the Symbol() constructor.
You can optionally provide a description, which is just for convenience
const RED = Symbol(); const ORANGE = Symbol("The color of a sunset!"); RED === ORANGE // false: every symbol is unique
11. null and undefined
null has only one possible value (null).
undefined has only one possible value (undefined).
Something hasn’t been given a value yet.
Both null and undefined represent something that doesn’t exist.
Note that if you declare a variable without explicitly giving it a value, it will have a value of undefined by default.
let currentTemp; // implicit value of undefined const targetTemp = null; // target temp null -- "not yet known" currentTemp = 19.5; // currentTemp now has value currentTemp = undefined; // currentTemp appears as if it had never // been initialized; not recommended
12. Objects
objects can represent multiple or complex values, and can change over their lifetime.
An object is a container, and the contents of that container can change over time.
The contents of an object are called properties (or members), and properties consist of a name (or key) and value. Property names must be strings or symbols, and values can be any type (including other objects).
const obj = {}; obj.size; // undefined obj.color; // "yellow"
To use the member access operator, the property name must be a valid identifier. If you want property names that are not valid identifiers, you have to use the computed member access operator (you can also use this for valid identifiers):
obj["not an identifier"] = 3; obj["not an identifier"]; // 3 obj["color"]; // "yellow"
You also use the computed member access operator for symbol properties.
const SIZE = Symbol(); obj[SIZE] = 8; obj[SIZE]; // 8
obj has pointed to the same object all along, but the object itself has changed.
const sam1 = { name: 'Sam', age: 4, };
const sam2 = { name: 'Sam', age: 4 }; // declaration on one line
const sam3 = { name: 'Sam', classification: { // property values can kingdom: 'Anamalia', // be objects themselves phylum: 'Chordata', class: 'Mamalia', order: 'Carnivoria', family: 'Felidae', subfaimily: 'Felinae', genus: 'Felis', species: 'catus', }, };
Objects can also contain functions.
sam3.speak = function() { return "Meow!"; };
we can delete a property from an object with the delete operator:
delete sam3.classification; // the whole classification tree is removed delete sam3.speak; // the speak function is removed
13. Number, String, and Boolean Objects
What JavaScript is doing is creating a temporary String object.
As soon as the function has been called, JavaScript discards the object.
'JavaScript' 카테고리의 다른 글
4일차 공부내용 2 (0) 2021.07.20 4일차 공부내용 (0) 2021.07.20 3일차 공부 내용 (0) 2021.07.19 2일차 공부 내용 (0) 2021.07.18 1일차 공부 내용 (0) 2021.07.17