Write in the beginning: personal “talent and learning”, small white one, the following content is the summary of notes in the learning process and personal feeling, if there is any mistake please correct

About the title: the title is the road to Cultivation. One is that I used to be a fan of fairy cultivation novels, and the other is that I was inspired by a book written by The great God Yang Yifei

Basic introduction to JavaScript – understand the JS continent


The book follows the text, the above mentioned variable naming norms and so on, and then variables to expand the following

Typeof (); typeof(); typeof(); The data type that can be used to get a variable

  • Data types can be converted to each other
    • There are two types of conversions involved: explicit (cast) conversions and implicit conversions
  • To a string:
    • The variable name. The toString (); — Explicit (mandatory) conversion
    • String(variable name); — Explicit (mandatory) conversion
    • + + concatenated string — implicit conversion (see usage below)
  • Convert to numerals:
    • Number(variable name); — Explicit (mandatory) conversion
    • Arithmetic operator (- * / %) operation conversion — implicit conversion (see usage below)
  • Convert to Boolean:
    • This situation is rare at present, and is commonly seen in conditional statements such as if and switch

The emphasis here is on implicit conversions of string and number types, especially the concatenation of + signs, which are used quite frequently

Categories discuss conversions between data types and conversion of special values:

  • String to number (conclusion first) :
    • There are two types of NaN: strings (strings that are not pure numbers (for example, ’12’) are of non-numeric, undefined type

    • There are three conversions to 0: “, “(space string), and NULL

    • Analysis: When a string is a pure number, it can be converted directly to a number. When a string contains non-numbers, It will get NaN(not a number) “/” (empty string and space string) will be parsed and 0 ‘1’ (1 preceded by a space) will be parsed to 1 and null (which is basically the same thing as an empty object) will be converted to 0 Undefined (that is, undefined data type) is converted to NaN

    • Note here: NaN is a type of number!!

  • When a number is converted to a Boolean value, only 0 or NaN is false, and all other numbers, including negative numbers, are true
    • Here this sentence every place is important!!
    • Only 0 or NaN is false: that is, the five cases where the other data types described above can be converted to a numeric type to get 0 or NaN and then converted to a Boolean will get false
    • There are five cases where converting to a Boolean is worth false: 0, NaN, ”, null, and undefined
    • The rest of the numbers are true including negative numbers: there is a misconception here that we, including those of you with programming background, generally think negative numbers should be false, but this is not the case in JS

    To sum up, the logic for the rest of the conversion to a Boolean is to determine whether the content is empty or NaN. If it is empty or NaN, it will get false. If the box contains content (Here is a very simple example to illustrate the logic: "space string converted to a Boolean is true!! The reason is that Spaces actually occupy memory! An empty string converted to a Boolean value is false, because empty strings actually have no memory!)

Expand knowledge:



Here’s a little bit about data storage:

  • Data storage unit
    • 1. A bit can hold either a 0 or a 1 (the smallest unit of storage).
    • Byte: 1B= 8B
    • Kilobytes (KB) : 1KB=1024B
    • Megabytes (MB) : 1MB=1024KB
    • Gigabytes (GB) : 1GB=1024MB
    • Terabyte (TB) : 1TB is 1024GB

    .

We often use the computer all know, the general file will have a size, in transmission, the common KB, MB, GB and so on but as a qualified programmer, understand the computer its actual some storage units and principles I think it is still very necessary. As we know, the computer is a machine, and all its activities are carried out by 0 and 1. The Boolean value mentioned above is actually a manifestation of 0, 1 of the computer. And store the memory size of a 0 or a 1, is the smallest unit of storage in a computer is bit, as we are typing on the computer, English, Chinese, etc., by a method of artificial convert it into binary computer is able to identify (ASCII value is a very good show, for example, each corresponding to a kind of symbol number, The storage unit that can hold such a character is called Byte, a Byte is equal to 8 bits of bit, that is, an 8 bits of binary value.

Arithmetic operator

  • There are five arithmetic operators, and only numbers are involved in the process (this rule is the reason for the implicit conversion of numbers)
    • + : addition operation (string concatenated with + sign cannot be called arithmetic operation, but can only be understood as a function of +)
    • – : subtraction operation
    • * : multiply operation
    • / : divide
    • %: modular (mod) operation (that is, the remainder is obtained)

Note: Distinguish between the two different uses of the + sign! Here are some questions that often arise:

var a = 1; var b = 2; var c = '3'; console.log(a + b + c); Console. log(c + b + a); console.log(c + b + a); console.log(c + b + a); (c + b + a) (c + b + a) (c + b + a)Copy the code

Ps: There is another important point to note in advance: any variable is determined at the time of assignment,Unless the variable type is changed again by assignmentOtherwise, any operation or implicit conversion will only change its type in the current operation, and will not change the data type of the variable itself !!!!!

Three output statements of JS

  • Alert (single parameter):Prints a popover on the page
  • Console. log(can output multiple arguments):Output at the console
  • Document. write(can output multiple arguments):Output on the page (document)

Logical judgment operator

Boolean operators are operators that perform Boolean operations and return Boolean values. Later developments are often used to determine multiple conditions

&& and | | or! nonCopy the code

Key points in logical operators:

Short-circuit operation (logical interruption) principle: When there are multiple expressions (values), the expression value on the left can determine the result, the expression value on the right will not continue to calculate

If the value of the first expression is true, return expression 2. If the value of the first expression is false, return expression 1. : or logical expression is 1 | | expression if the value is true, the first expression expression returns 1 if the first value of the expression is false, it returns expression 2 people speaking: logic or - is really trueCopy the code

Short circuit operation: to improve the speed of the system operation.

Comparison operators:

< less than > greater than <= Less than or equal to >= Greater than or equal to == equal to (the default conversion data type is alphanumeric)! === =! == congruent (requires consistent value and data type)Copy the code

Conclusion:

== assign the value from the right to the left == Determine whether the values on both sides are equal (note that there is an implicit conversion) === congruence Determine whether the values and data types on both sides are identicalCopy the code

Li’s secret formula: single equal value, double equal judgment, three equal congruence

Increment and decrement operators

++ -- incrementing decrement operator can be placed before or after a variable pre-incrementing operator: ++ written before a variable ++age // similar to age=age+1 incrementing operator num++ / similar to age=age+1 difference: 1. The pre-increment operator and the post-increment operator are the same if used alone 2. When used in combination with other codes, the execution result will be different. 3. Postincrement formula: Return the original value first, and then increment 1 and 4. In development, we mostly used the postincrement operatorCopy the code

The assignment operator

= +=, -= *=, /=, %=Copy the code

The priority of the operator

Note: Only part of the operators are listed here

1 parentheses () 2 unary operators ++, --,! 4 relation operator > >= < <= 5 equal operator ==! = = = =! = = 6 logical operators && before | | 7 the assignment operator = 8 comma operator,Copy the code

Li’s secret formula: a calculation operation, equal logic comma.

Var I = 10,j; var I = 10,j; var I = 10,j; var I = 10,j; var I = 10,j; j = i++ ; Why does console(j) output 10 instead of 11, and doesn’t that result violate the precedence order of the operator?

The answer will be attached to the Blog next Tuesday or Wednesday, please pay attention!


Thank you to see the officer can see here (pretend to have), interested in words as well as a key three even oh ❤️~