8. Type Coercion and Short-Circuit Evaluation

What is Type coercion?

  • Explicit coercion / Type casting: developer intentionally converting value types

    1
    2
    3
    var x = 10;

    var str = x.toString();
  • Implicit coercion / Type coercion: Type automatically converted by the JavaScript engine regardless of developer intent.

    1
    2
    3
    4
    5
    var x = 10;

    var str = x + '';

    // x = Number 10, str = Sring 10

    Does reassignment occur when type coercion occur?

    No. It only takes a moment to type when evaluating expressions.

The developer can use implicit type conversion intentionally.

7. Control Flow Statement

  • Controls the flow of code that runs sequentially from top to bottom.

  • Control statements make the flow of code difficult to understand, which detracts from readability.

  • Should suppress the use of control statements with using high order functions (map, filter, reduce, forEach)

6. Operator

Expression and Operator

Operator needs operand as value. And the expression is equivalent with value. So expressions can be located

Values ​​can be generated in a variety of ways. The various methods mentioned here are expressions. Expressions in a programming language have a very important meaning.

Expression is combination of tokens(literal, identifier(variable name, function name, etc), operator, function call). The expression is evaluated to produce a single value. That is, an expression is a statement that can be evaluated as a single value.

Expression can be divided into a literal notation, an identifier expression, an operator expression, a function/method call expression, but they are all the same in that they are evaluated and made into a single value.

The value that generated by evaluation of an expression is equivalent with an expression. In other words, expressions can be used like values. This means that an expression can also be placed where the value can be placed.

5. Data Type

What is Data Type?

Data Type is type of values. All of the data in JavaScript have data type.

Allocatation of memory space by Data Type

All of values used in programming language can be stored in memory and referenced. To store values in memory, computer need to know the size of memory space it need. Because size of memory depends on data type.

JavaScript uses a double-precision 64-bit floating-point format when creating numeric binary values.

Access memory by Data Type

When refer to memory space by identifier, computer need to know the size of memory it need to read once. If variable soup is Number type, computer should access memory by only 8 byte. Data Type provides that informations to computer and human.

Here’s reasons why Data Type need:

  1. To determine the size of memory space that must be free when storing values
  2. To determine how much memory space should be read at once when referring to a value
  3. To determine how to interpret the binary be read from memory. (To Number, String etc.)

4. Variable

What is variable?

Application uses data. And the variable is core concept for managing data.

Computer is computing machine. To do simple operation like sum of 1 and 2, computer should memorize these operand 1 and 2 in register. Computer uses memory to memorze the data.

3. JavaScript Develop Environment and Execute

Before this chapter, What is Web API?

While the most common scripting language ECMAscript (more widely known as JavaScript) is developed by Ecma, a great many of the APIs made available in browsers have been defined at W3C.

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×