JavaScript 시작하기 - 2장 🚀

목차
* 🤓 INTRODUCTION
* 🔢 NUMBERS IN JAVASCRIPT
* 🅰 STRINGS
* ✅ BOOLEAN VALUES
* 💡 LOGICAL OPERATOR
* ❓ TERNARY OPERATOR
* EMPTY VALUES
* 🦾 AUTOMATIC TYPE CONVERSION
* 📝 SUMMARY
* ➕ APPENDIX 1
* 🙏 THANK YOU

🤓 소개

**Welcome, my dear coders! I hope you are all having a codelicious day! Here we are, our second chapter of the Getting started with javascript series. Yesterday, we went through the basic idea of the JavaScript programming language. Today we are going to dive a bit deeper, and maybe tackle the topics mentioned yesterday a bit more.

Let's with the basics, how JavaScript thinks of numbers.


🔢 자바스크립트의 숫자

Values of the number are numeric values (like we didn't know that 😂). When you type up the number in your program, it will cause the bit pattern for that specific number to come into existence inside the computer's memory.

JavaScript uses a fixed number of bits, 64 of them, to store a single number value. There are only so many patterns you can make with 64 bits, which means that the number of different numbers that can be represented is limited.

➗ 그 뒤에 숨은 수학



N개의 십진수가 있는 경우 10의 N제곱 - 10N을 나타낼 수 있습니다. 마찬가지로 64개의 이진수가 주어지면 264개의 숫자를 나타낼 수 있으며, 이는 약 18조 또는 18000000000000000000개의 숫자입니다. 많은 숫자! 오늘날의 포켓 컴퓨터(휴대폰)를 사용하면 64비트 청크를 쉽게 사용할 수 있으며 진정한 천문학적 숫자를 처리할 때만 오버플로에 대해 걱정하면 됩니다. 그러나 18조 미만의 모든 정수가 JavaScript 숫자에 맞지는 않습니다. 이러한 비트는 또한 음수를 저장하므로 1비트는 숫자의 부호를 나타냅니다. 더 큰 문제는 정수가 아닌 숫자도 표현되어야 한다는 것입니다. 이를 위해 일부 비트는 소수점 위치를 저장하는 데 사용됩니다.

따라서 저장할 수 있는 실제 최대 정수는 9,000조(0의 15개) 범위에 있습니다. 꽤 큽니다!

앞서 언급한 9,000조보다 작은 정수(정수라고도 함)를 사용한 계산은 항상 정확함을 보장합니다. 불행히도 분수 계산은 일반적으로 그렇지 않습니다.

🧮 산술



숫자와 관련된 주요 작업은 산술입니다. 더하기 또는 곱하기와 같은 산술 연산은 두 개의 숫자 값을 사용하여 새 숫자를 생성합니다. 예를 들어:

11 + 213 * 11

+ 및 * 기호를 연산자라고 합니다. 첫 번째는 더하기를 나타내고 두 번째는 곱하기를 나타냅니다. 두 값 사이에 연산자를 넣으면 해당 숫자 값에 연산자가 적용되고 새 숫자 값이 생성됩니다. 실제 수학처럼 곱셈이 우선입니다! 뺄셈에는 - 기호가 붙습니다.

연산자가 괄호 없이 함께 나타날 경우 연산자의 우선 순위에 따라 적용 순서가 결정됩니다.

*와/는 우선순위가 같습니다. + 및 - 연산자도 마찬가지입니다. 우선 순위가 같은 연산자가 여러 개인 경우 왼쪽에서 오른쪽으로 적용됩니다.

중요한 산술 연산이 하나 더 있습니다. 기호 %로 표시된 나머지 연산. X%Y는 X를 Y로 나눈 나머지입니다.

🅰 자바스크립트의 문자열

As we mentioned yesterday, strings are used to represent text. They are written by enclosing their content in quotes:

var double_quotes = "Coding is fun!";
var single_quote = 'Coding is fun!';
var backticks = `Coding is fun!`;

Almost anything can be put between quotes, JavaScript will make a string value out of it. But a few characters are more difficult. For example, putting a new line (the characters you get when you press ENTER), can be only included without escaping only when the string is quoted with backticks.

Let's see an example:

var newline_string = 'Coding \n is fun!';
console.log(newline_string)
/*
OUTPUT:
Coding 
is fun!*/

There are situations where you want a backslash in a string to be just a backslash, not a special code. If two backslashes follow each other, they will collapse together.
Example:

var collapse = "Coding \"\\n\" is fun."
console.log(collapse)
/*
OUTPUT:
Coding "\n" is fun.
*/

Strings cannot be divided, multiplied, or substructed, but the + operator can be used on them to concatenate them.
Example:

var concat = "Coding" + "is" + "fun!";
console.log(concat);
/*
OUTPUT:
Codingisfun!
*/

✅ 부울 값

It is often useful to have a value that distinguishes between only two possibilities, like "yes" and "no", or "on" and "off, or "true" and "false". For this purpose, JavaScript has a Boolean type, which has just two values, true and false (this is not a string this is a special type, no double quotes, single quote, or backticks are needed)

var boolean_value = true; //this is a boolean value
var string_value = "true"; //this is a string value

Let's use it in a real example.

console.log(3 > 2); //output: true
console.log(3 < 2); //output: false

💡 논리 연산자

There are also some operations that can be applied to Boolean values themselves. JavaScript supports three logical operators: AND, OR, NOT.
Examples:

console.log(true && false); // output: false
console.log(true && true); // output: true
console.log(true || false); // output: true
console.log(true || true); //output: true
console.log(false || false); //output: false

❓ 삼항 연산자

A conditional operator (or sometimes called the ternary operator since it is the only such operator in the language). The value on the left of the question mark "picks" which of the other two values will come out. When it is true, it chooses the middle value, and when it is false, it chooses the value on the right.

console.log(true ? 1 : 2); // output: 1
console.log(false ? 1 : 2); // output: 2

빈 값

There are two special values, written null and undefined, that are used to denote the absence of a meaningful value. They are themselves values, but they carry no information.

Many operations in the language that don’t produce a meaningful value yield undefined simply because they have to yield some value.

🦾 자동 유형 변환

JavaScript goes out of its way to accept almost any program you give it, even programs that do odd things.
For example:

console.log(10 * null); //output: 0
console.log("5" - 1); //output: 4
console.log("5" + 1); //output: 51
console.log("five" * 2); //NaN
console.log(false == 0); //true

When an operator is applied to the “wrong” type of value, JavaScript will quietly convert that value to the type it needs, using a set of rules that often aren’t what you want or expect. This is called type coercion. The null in the first expression becomes 0, and the "5" in the second expression becomes 5 (from string to number). Yet in the third expression, + tries string concatenation before numeric addition, so the 1 is converted to "1" (from number to string).

📝 요약

  • Values of the number are numeric values
  • JavaScript uses a fixed number of bits, 64 of them, to store a single number value.
  • If you had N decimal digits, you can represent ten to the power of N numbers - 10N
  • Not all whole numbers less than 18 quintillions fit in a JavaScript number. Those bits also store negative numbers, so one bit indicates the sign of the number. A bigger issue is that nonwhole numbers must also be represented. To do this, some of the bits are used to store the position of the decimal point.
  • Putting an operator between two values will apply it to those number values and will produce a new number value.
  • If operators appear together without parentheses, the order in which they are applied is determined by the precedence of the operators.
  • Strings cannot be divided, multiplied, or substructed, but the + operator can be used on them to concatenate them
  • JavaScript supports three logical operators: AND, OR, NOT
  • Many operations in the language that don’t produce a meaningful value yield undefined simply because they have to yield some value.

➕부록 1 - 논리 연산자 시각적 표현



이미지에서 다음과 같은 결론을 내립니다.
  • OR은 X 또는 Y가 참일 때마다 참입니다.
  • 배타적 OR은 X가 참이거나 Y가 참인 경우에만 참입니다.
  • AND는 X가 참이고 Y도 참인 경우에만 참입니다.

  • 🙏 읽어주셔서 감사합니다!

    References:
    School notes...
    School books...

    Please leave the comment, tell me about you, about your work, comment your thoughts, connect with me!

    ☕ SUPPORT ME AND KEEP ME FOCUSED!


    즐거운 해킹 시간 되세요! 😊

    좋은 웹페이지 즐겨찾기