Javascript tutorial simple summary

What is the function

     Defined section of code, and the code blocks can be used repeatedly

Function returns

     Enhance the reusability of code, a code will be pre-defined, used only when needed to trigger

Block

     Forming a relatively independent scope

grammar:

      function function name (parameter list) {

    Code block (function body);

    return return value

  }

  Function name (function call)

End of the function:

     After the program hit return, behind the return codes will no longer perform, and at most only one return value

 

For now, I have known function

  isNaN()

  prompt()

  parseInt()

  parseFloat()

  charcodeAt()

  toString()

  Number()

  document.write(‘’)

  toFixed()

  alert()

  console.log()

 

What is the scope

  A range, also known as life-cycle variables

 

JS in the scope of classification

  1. function scope

     This variable can only be accessed in the current scope, the current function is accessible

    Variable using the var keyword in the body of the function is a local variable

  2. The global scope

    Once defined, the code can access anywhere

 

What is an array

  Continuous memory storage space to store more data, unified name

Why use an array

  Compile multiple arrays stored continuously maintain and query

how to use

  1. Create an empty array

    Can not start with a number, you can not use keywords and reserved words, you can use underscores, letters, numbers and $

    was = array [];

    If this was [] it is to create a new array

  2. Create an empty array of a number of known data

    Create an array to store already exists but does not currently know of contents

    var a = new Array (positive integer);

  3. Create an array of content initialize an array at the same time

    var name =  [ ' ' , ' ' , ' ' ];

    Direct input array quotes

How to Access

  By subscript subscripted array element number stored in a location, default scratch, will not be repeated continuously

 

feature

  Does not limit the type of data storage elements, the out of range target, the number of array elements

  .length properties, recording the number of array theory, the last element is +1, because the first array is 0

   How to add a new element to the end of the array

  array [array.length] = 'element name';

  Gets the last element of the inverse of the n-th element

  array[array.length - n ];

   Iterate perform the same operation on each element of the array

  var drinks = [ "pearl milk tea", "ice tea", "plum", "happy fat house water"];

  Read operation

  for(var i = 0;i< drinks.length;i++){

  console.log(drink[i]);
  }

  A cycle length of 10 to random assignment of data

  var nums = new Array(10);

  for(var i =0 ;i<nums.length;i++){

  nums[i] = (Math.random()*10) | 0;

  }

  console.dir(nums);

  

  Primitive types: number string boolean undefiend null

  Local data directly stored in the variable data types

  Passed by value: when the assignment between two variables or variable as a parameter passed to the function, in fact, only the value of the original variable assignment to a copy of the   

  The other party to modify the new variables will not affect the original variable values

  Reference types: Data can not be saved directly in the data type of the local variable

  Because the variable is allowed to save a value, and reference types are often simultaneously hold multiple values

  It will be outside the window object, creating a separate memory space, and each individual has a unique storage space

  Variable still preserved is a value, but only to save the array address it - called reference

  Delivery is the address (actually passed by value, but the value is an address): Modify the new array, equivalent to directly modify the elements of the array

 

 

Guess you like

Origin www.cnblogs.com/jiapei/p/11246917.html