Function scope, return the return value, a recursive function, built-in functions top, cast data, implicit data type conversion

Scope of a function

Global Variables

在页面的任何地方都能访问到的变量,拥有全局的作用域
  1. The outermost layer of the variables defined functions
  2. There is no direct variable assignment with Global Properties

Local variables

只能在固定的代码片段中访问到
  1. Variables defined inside the function;
  2. Parameters are also local variables

return

To a function returns a value, and terminates the current function out

return return value
  1. The return value can be any data type
  2. You can only return a return value
  3. If no return value, the default value is undefined

recursive function

It calls itself inside the function

JavaScript functions built top

  1. escape () non-alphanumeric characters are encoded

  2. unescape () for decoding the encoded string

  3. Number () is converted into numeric types
    1. If it is a Boolean value, false is 0, true 1
    2. If it is digital, converted into itself. The rear guide meaningless 0 removed.
    3. If null converted to 0
    4. If this is undefined is converted to NaN not a number
    5. If a string
      1. If a string which only the number is converted to decimal (0 ignore leading and trailing guide 0)
      2. If the norm is valid floating-point, floating-point value is converted into (0 ignore leading and trailing guide 0)
      3. If the string is empty, then converted to 0
      4. If other values, return NaN
  4. String () is converted into a string type
    1. You may convert any type String
    2. null and undefined: will be converted to a string, are null and undefined
    3. Boolean: true and false returns
    4. Value Type: string itself
  5. Boolean () is converted into Boolean type
    1. Conversion is false: "", 0, NaN, undefined, false, null
    2. Others are converted to all true.
  6. the parseInt () to convert the string to an integer
    1. If a string contains only numeric, decimal places conversion manner integer
    2. Automatically ignore spaces in front of the string until it finds the first non-empty string value, if the first character string is not a space, digital, - then return NaN
  7. parseFloat () is converted to a decimal
    1. Among the string of only the first valid, others are invalid
    2. If the string is a valid integer, his return is an integer, floating point numbers will not return
  8. () Determines whether a number is converted to numeric type isNaN
    1. If the energy is converted to the value FALSE, the type of value that can not, returns true

JavaScript data cast

  1. Number () is converted into numeric types
  2. String () is converted into a string type
  3. Boolean () is converted into Boolean type
  4. the parseInt () to convert the string to an integer
  5. parseFloat () is converted to a decimal

Data type conversion Implicit

  1. Arithmetic Operators
  2. Relational Operators
  3. Logical Operators
  4. if
  5. while
  6. A triplet of expressions

Guess you like

Origin www.cnblogs.com/liuxuhui/p/12157134.html