JavaScript Review (1)

The basic concept of 1.JavaScript

  1. JavaScript is an interpreted scripting language
  2. JavaScript can write anywhere inside the HTML document
  • Inline style
  • Inner fitting formula
  • Chain-in:<script src="">链入式其标签内部的代码不会被执行</script>

The basic syntax of 2.JavaScript

variable

Use var to declare variables, js does not exist in int, float, bool, double, declare any type of variables with the var
named variables:
  1. You can use $, underscores, beginning with the letter
  2. After the first character can use numbers, $ , underlined letters

js Data Type: divided into two categories, basic data types & reference data types

Basic data types: number, string, boolean
reference data types: Object
undefined, null:

  1. null represents a null value, the value did not exist
  2. undefined represent unknown, indicates an unknown object state
  • 1. When a variable is only a statement, but there is no assignment, the status of this variable is undefined rather than null
  • 2. When a function does not return a value, it will return undefined
js里引用类型允许动态添加字段
例如:
var obj = new Object();
obj.name = "淘宝";
obj.age = "16";
obj.address = "浙江杭州";
alert("大家好,我叫"+obj.name+",我今年"+obj.age+",我来自"+obj.address);
js动态数据类型: 
例如:
var bt;
bt = 125;
console.log(typeof(bt));
bt = "BT";
console.log(typeof(bt));
bt = true;
console.log(typeof(bt));

Variable scope

  1. A page in a different variable is declared can not visit each other
  2. js no variable naming conflicts, but after a variable declared in front of the same name will overwrite variables
  3. js no concept of block-level scope
  4. Variables can also be directly used without declaration assignment (in the function if you do not declare a global variable that is, if a local variable is declared)

Flow control statements

  • if……else
  • for
  • while
  • do……while
  • switch:
     can not break (if not break program execution will always go on) after 1. js switch statement in Case
     2. switch judgment here is congruent (===)

js the sentence like: "==" (equal), and "===" (congruent)

==: comparing only content, data type without comparison (conventional)

var num1 = 123;
var num2 ="123";
if(num1 == num2){
    console.log("相等");
}
else{
    console.log("不相等");
}
结果为:相等

===: stricter than for content and data types

var num1 = 123;
var num2 ="123";
if(num1 === num2){
    console.log("相等");
}
else{
    console.log("不相等");
}
结果为:不相等

pop-up dialogue box

  • alert ( ""); warning message box
  • prompt ( ""); confirmation message box: a pop-up text input box data type string
  • confirm ( ""); messageboxes

Operator "+" and "-"

The role of "+":
  1. arithmetic sum, provided that the two operands are of the type of number
  2. The string concatenation, if the number is not a number of types, then the "+" will be connected to a string

var num = 100;
var str = "20";
console.log(num + str);
输出:10020

"-": the arithmetic subtraction

var num = 100;
var str = "20";
console.log(num - str);
输出:80
var num = 100;
var str = "true";
console.log(num - str);
输出:NaN:Not a Number 不是一个数

Guess you like

Origin www.cnblogs.com/discourage/p/11488910.html