1-10

Variable is not a specific value, but a container or pronoun used to store a specific value. Because the value stored in it can be changed, it is called a variable

Var (ES3) -function (ES3) -function (ES3) -function (ES3) -function (ES3) -function (ES3) -function (ES3) -let (ES6) -const (ES6) creates a constant -import (ES6) based on ES6 module specifications export required information - class (ES6) creates a class based on ES6Copy the code

Let = const const function () {} function () {}

``` var n = 13; n = 15; alert(n+10); //=> 25 const m = 100; m = 200; // => Uncaught TypeError: Assignment to constant variable. A constant cannot be reassigned (a value stored in a constant cannot be modified, which is a variableCopy the code

Seven: Create variables that follow a few conventions when naming them – strictly case sensitive – following the camel’s name: According to the Numbers, letters, underscores, named (digital as the beginning of the name), named based on English words when joining together into a full name (letters lowercase for the first word and the rest every meaningful words the first letter of capital – cannot use keywords and reserved words, the future may be a key word is called a reserved word

var n = 12; var N = 13; Var studentInfo/student_info / _studentInfo (public variables) /$studentInfo(Typically JQ elements are stored).. more semanticCopy the code

Eight: Data values are one of the following types

  • Basic data types (value types)
    • Word number
    • String string
    • Boolean Boolean
    • null
    • undefind
  • Reference data type
    • Object the object
      • Ordinary objects
      • The array object
      • Regular object
      • The date object
      • .
    • Function is the function
  • New to ES6 is a special type: Symbol, a unique value
Var n =13; //=>0 -13 13.2 There is a special value NaN(not a number means not a valid number, but is of type number) var s =' '; / / = >""   "13"  "{}"Var b = all strings that are enclosed in single or double quotation marks are strings that contain the characters in the current string (a string consists of zero to multiple characters)true// => Boolean types have only two valuestruetruefalseVar o ={name: 'madero, age: 9}; Var ary = [12,23,34,45]; var ary = [12,23,34,45]; Var reg = /-? Var reg = /-? (\d | ([1-9]\d+)) (\. \d+)? /g //=> consists of metacharacters to form a complete re //=> is not an empty re but a single-line commentfunction  fn(){} [Symbol] creates a unique value var a = Sybol()'Madder Road 1'); var b= Sybol('Ma Delu 2 '); a==b= >false
Copy the code

Extensions: How the JS code is run and how it outputs the result after it is run [how it is run] – Run the code in a browser (the browser kernel renders and parses it) – Run it in NODE (NODE is also a tool for rendering and parsing JS based on V8) – [How it outputs the result] – alert: Var num = 12; Alert (num); // => window. Alert var STR = ‘window’; alert(str);

alert(1+1); Alert (true) => '2'; alert(true) => '2'; = > 'true' alert ([12, 10]); '12, alert ({name: "XXX"}); =>'[object object]' toString returns object object. Var flag = confirm (' Do you want to return this item? '); '); If (flag){//=>flag:true User clicks ok button}else{//= "flag:flase user motor is cancel button} ' '-prompt: add input box based on confirm - console. log: F12 (FN+F12) is used to open the browser Console. Console, you can print.log in JS code here, or you can write JS code directly here + Sources: the current site source files are in here - console.dir: - console.table: Outputs JSON data as a table -.. (go back and extend console output methods)Copy the code

Flase is a valid number. Flase is a valid number. Flase is a valid number

//=> syntax: isNaN([value]) var num = 12; isNaN(num); //-> Check whether the num variable stores a value that is a significant numberfalse

	isNaN('13') = >false
	isNaN(true) = >false 
	isNaN(true) = >false 
	isNaN(null) =>false
	isNaN(undefind)=>true
	isNaN({age:9}) => trueIsNaN ([12, 10]) = >true 
	isNaN([12]) 
	=>false 
	isNaN(/^$/) =>true
	isNaN(function() {}) = >true1. First verify that the value currently being tested is numeric. If not, the browser will convert the value to numeric by default. Convert non-numeric values to numbers - other basic types to numbers: convert string to Number (string to Number)'13') ->13
			Number('13px'If any non-valid numeric character occurs in the current string, the result is NaN Number('13.5')->13.5 can recognize decimal [Boolean to Number] Number(true)->1
			Number(false)->0 [other] Number(null)->0 Number(undefined)->NaN - ToString (); toString(); toString(); toString();'[object object]'->NaN [array] [12,23].tostring ()->'12,->NaN
			[12].toString()->'12'->12
			[正则]
				/^$/.toString()->'/^$/'->NaN

			Number(' ')->0
			[].toString()->' '=>isNaN([]); 2. The value currently detected is already numeric and is returned as a significant digitfalseNot returntrue(Only NaN is not a valid number among numeric types,)Copy the code

2. ParseInt/parseFloat is equivalent to Number, which is also used to convert other types of values to numbers. The difference between Number and parseFloat is the string conversion analysis of Number: any non-valid numeric character occurs, resulting in a NaN

ParseInt: parseFloat resolves the integer part of a string. ParseFloat resolves the small (floating point) part of a string

   parseInt('13.5 px.) =>13
   parseFloat('13.5 px.The parseInt () = > 13.5'width: 13.5 px.) =>NaN looks for a valid numeric character starting with the leftmost character of the string, and converts it to a number, but as soon as it encounters an invalid numeric character, the search endsCopy the code
  1. The comparison of NaNCopy the code
	NaN==NaN;   falseNaN was not equal to anyone, including himselfCopy the code

Question: there is a variable num, the value of the store does not know, I want to check whether it is a significant number, the following scheme can be

	if(Number(num)==NaN){
		alert('num is not a significant number '); } is not equal to anyone, and the condition is never really true (even if num is not a significant number and the result of the conversion is indeed NaN, but NaN! = NaN)if(isNaN(num)){//=> check whether the number is a significant number.'num is not a significant number ')}Copy the code

Boolean type

There are only two values: true/false

How do I convert other data types to Booleans?

  • Boolern
  • !
  • !!!!!
Boolean(1) = >true
!Madeira Road=> Convert other data types to Booleans first, then invert!!null= >If you take two inverts, that's the same thing as taking no inverts at all, you're just left with a Boolean conversionCopy the code

In JS only: 0/NaN/ empty string /null/undefined => These five values are converted to Boolean false, the rest are converted to true

###null &&undefined

Represents an empty

  • Null: Indicates an empty object pointer
  • Undefined: undefined

Null: This is usually not expected.

	var num =null;  //=>null is a manual assignment, so I will change the value of num variable later. num =12;
Copy the code

Undefined means none. It is usually not manually controlled, and most of it is left blank by the browser.

	var num;  //=> The value of the variable assigned by the browser is undefined
	undefined. It may or may not be assignedCopy the code

This is the QQ group I built there are a lot of resources, I hope to study with you to discuss common progress!

This is the group number :778734441

I will also share better information to you, I hope you support, I will release a lot of excellent works out!!