Expressions and operators

Alpaca·2021년 6월 15일
0

Javascript

목록 보기
3/6

TL;DR

여태 js를 공부하면서 expression, statement 그리고 operator에 대한 기본개념이 없는 것 같아 정리해보았다

Expression

Any unit of code that can be evaluated to a value is an expression.

"값으로 평가될 수 있는 모든 코드 단위는 표현식이다"

Arithmetic Expressions

Arithmetic expressions evaluate to a numeric value.

"산술표현식은 수로써 평가되는 표현식이다"

10; // Here 10 is an expression that is evaluated to the numeric value 10 by the JS interpreter
10+13; // This is another expression that is evaluated to produce the numeric value 23

javascript interpreter에 의해 1010이라는 숫자값으로 평가되고
10+1323으로 평가된다

String Expressions

String expressions are expressions that evaluate to a string.

"문자열 표현식은 문자열로써 평가되는 표현식이다"

'hello';
'hello' + 'world'; // evaluates to the string 'hello world'

Logical Expressions

Expressions that evaluate to the boolean value true or false are considered to be logical expressions.

"불리언 값(참 혹은 거짓)으로 평가되는 표현식은 논리표현식이다"

10 > 9; // evaluates to boolean value true
10 < 20; // evaluates to boolean value false
true; // evaluates to boolean value true
a===20 && b===30; // evaluates to true or false based on the values of a and b

Primary Expressions

Primary expressions refer to stand alone expressions such as literal values, certain keywords and variable values.

"기본 표현식은 리터럴 값, 특정 키워드 및 변수 값과 같은 독립 실행형 식을 나타낸다"

'hello world'; // A string literal
23; // A numeric literal
true; // Boolean value true
sum; // Value of variable sum
this; // A keyword that evaluates to the current object

Left-hand-side Expressions

Also known as lvalues, left-hand-side expressions are those that can appear on the left side of an assignment expression.

"할당식의 왼쪽에 있는 식을 Left-hand-side Expressions이라고 한다"

// variables such as i and total
i = 10;
total = 0;

// properties of objects
var obj = {}; // an empty object with no properties
obj.x = 10; // an assignment expression

// elements of arrays
array[0] = 20;
array[1] = 'hello';

// Invalid left-hand-side errors
++(a+1); // SyntaxError. Attempting to increment or decrement an expression that is not an lvalue will lead to errors.

Assignment Expressions

When expressions use the = operator to assign a value to a variable, it is called an assignment expression.

"표현식에서 =연산자를 사용하여 변수에 값을 할당하는 표현식을 할당 표현식이라고 한다"

average = 55;
var b = (a = 1);
// here the assignment expression (a = 1) evaluates to a value that is
// assigned to the variable b. b = (a = 1) is another assignment expression.
// var is not part of the expression.

varexpression에 해당되는 부분은 아니다

Expressions with side effects

sum = 20; // here sum is assigned the value of 20
sum++; // increments the value of sum by 1
function modify(){
  a *= 10;
}
var a = 10;
modify(); // modifies the value of a to 100.

위와 같이 기존의 할당 값이 변화할 수 있는 부작용이 있을 수 있으므로 주의하여야 한다

Statements

A statement is an instruction to perform a specific action.

"문은 특정 작업을 수행하기 위한 명령이다"






reference
MDN: Expressions and operators
Medium: Javascript Expressions and Statements

profile
2020년 10월 15일 퇴사하고 개발자의 길에 도전합니다.

0개의 댓글