JavaScript study notes two identifier-character type

1. Identifier

1. Identifier

In JS, everything that can be named independently by us can be called an identifier, for example: variable names, function names, and attribute names are all identifiers.

2. The naming rules of identifiers

1. The identifier can contain letters, numbers, _, $.
2. The identifier cannot start with a number
3. The indicator cannot be a keyword or reserved word in ES.
4. Identifiers generally adopt camel case nomenclature (the first letter is lowercase, the first letter of each word is uppercase, and the remaining letters are lowercase, zzzYyyWww)
Insert picture description here

3. Identifier encoding

The Unicode encoding is actually used when storing identifiers at the bottom of JS, so in theory, all the content contained in utf-8 can be used as identifiers. Chinese can also be used as variable names, but never use them.

Two, character type

1. Character type classification

Refers to the type of literal. There are six character types in JS:

  • String
  • Number
  • Null
  • Boolean
  • Undefined
  • Object object

Among them, String, Number, Null, Boolean, and Undefined are basic character types, and Object is a reference character type.

2. String

  • In JS, the string needs to be enclosed in quotation marks, single or double quotation marks can be used, but do not mix them.
	var a="hello";
			console.log(a);
  • Quotation marks cannot be nested between quotation marks, double quotation marks cannot be placed in double quotation marks, and single quotation marks cannot be placed in single quotation marks. But you can put double quotation marks inside single quotation marks, and single quotation marks inside double quotation marks.
var a="我说:'今天天气可真冷啊!!!'";
			console.log(a);
  • You can use \ as an escape character in a string, and when it represents a special symbol, you can use \ to escape, which simply means that this is a symbol.

'Means''means' \n means newline; \t means tab character, tab space\ means \

var a="我说:\"今天天气可真冷啊!!!\"";
			console.log(a);

3. Number type

(1) The difference between numbers and strings

In JS, all numbers are of Number type, including integers and floating-point numbers (decimals).

  • 10 represents a number, literal
  • "10" represents a string String:
var a=10;
var a="10";
两者在控制台上面运行结果一样

(2) Distinguish the type of variables with the same operation result typeof

The typeof operator is used to check the type of a variable.
Syntax: typeof variable;
when checking a string, it will return string
when checking a value, it will return number

            //10是数字,字面量
            var a=10;
			console.log(typeof a);
			//10是字符串
			var a="10";
			console.log(typeof a);
运行结果:
[day01] 19:49:57.338 number at day1-js语法.html:14
[day01] 19:49:57.338 string at day1-js语法.html:17

(3)Number.MAX_VALUE

1. The largest number in JS is Number.MAX_VALUE
2. If the number represented exceeds Number.MAX_VALUE, a positive number returns Infinity positive infinity; negative number returns -Infinity negative infinity
3. Use typeof to check Infinity will also return number type.

console.log(Number.MAX_VALUE);
1.79769e+308

(4)Number.MIN_VALUE

1. The smallest number in JS is Number.MIN_VALUE

console.log(Number.MIN_VALUE);
"5e-324"返回0以上的最小值

(5) NaN

When multiplying two strings, the result will return a special number NaN, which means Not a Number. Although NaN is not a number, when you use typeof to check the types of NaN, the returned value is the Number type.

(6) Number operation

  1. The calculation of integers in js can basically guarantee accuracy.
  2. If you use js for floating-point operations, you may get an inaccurate result, so do not use js for high-precision operations, especially decimals.

4. Boolean

1. There are only two Boolean values, which are mainly used for logical judgment :
true: true false: false
2. When using typeof to check the literal true, the returned value is Boolean.

var a=true;//不加引号是字面量布尔值,加了引号就是字符串了。
console.log(typeof a);
返回值为"boolean"

5. Null

1. There is only one value for controlling null, which is null, which is specifically used to represent an empty object.
2. When using typeof to check for null, the returned type is object

6. Undefined

1. There is only one value of undefined type, which is undefined. When we declare a variable but don't assign a value to this variable, then the value of this variable is undefined.

2. When using typeof to check the variable, then the return value type of the variable is undefined.

Guess you like

Origin blog.csdn.net/weixin_45636381/article/details/112305990