JS haveEight data types, respectively,

Seven primitive types (simple types)šŸ§  To remember:

  1. Boolean Boolean value
  2. Number Number type
  3. String String
  4. Null Null
  5. Undefined empty
  6. BigInt Indicates the number type
  7. Symbol of symbols

And the only complex type:

  1. Object Understand the Object first

Arrays, functions, dates, they all belong to Object. Eight data types, five falsy values to remember.

— Source: Hungry Man Valley, MDN

Something to say

This article briefly documents the basic data types of JavaScript. If you are an experienced person who wants to fill in the gaps, if you are a novice like me, then my series of notes will be very helpful to you. If you want a quick look at JavaScript, it is recommended to go directly to the documentation JavaScript MDN. You can use the browser console or Jsbin to try out code quickly and easily. I wish you an early achievement.


1. BooleanBoolean value

Bool (very simple, no need to go into detail)

  • Bool origin

The bool is the name given to the two most basic values (true and false) by George Boole, a pioneer of mathematical logic.

It’s not Boolean algebra that makes the name Bool so well known, but Boolean variables. After the 1950s, almost every programming language had booleans, making the term “Boolean” popular. A good man dies because of his wife.

  • A bool has only two values

True and false are false (case sensitive)

  • The following operators yield bool values

ā‘  Negative operation

! value

Add! To a value. , means take the inverse

ā‘” Equal operation

1 == 2, 1! = 2, 3 == 2, 3 == 3 = = 4

If 1 == 2, get false, 1! = 2 = true, 3 === 4 = false, 3! == 4 returns true

ā‘¢ Comparison operation

1 > 2, 1 >= 2, 3 < 4, 3 <= 4

False, 1 >= 2 false, 3 < 4 true, 3 <= 4 true

Boolean Boolean value

  • If with a bool

If statements often need to be checked for true or false

If (value) {… } else { … }

The question

It’s fine if value is a bool

What if value is not a bool? Who’s true? Who’s false

1 is true or false, 0 is true or false

‘1’ is true or false, ‘0’ is true or false

  • Five Falsy values * šŸ§  to remember

Falsy is a value equal to false but not false

There are five false values to remember, and these five falsy values are false

Undefined null 0 NaN ”(empty string, note ” and ”)


2. Number Number type

A numeric data type defined in JavaScript as a 64 – bit double – precision floating-point type.

In other programming languages, different numeric types exist, such as Integers, single-precision Floats, Doubles, and Bignums.

He has many different ways of writing it

  • Integer *

1

  • Written as a decimal *

0.1

  • Scientific notation *

1.23e4, which is 1.23 times 10 to the fourth

  • Octal notation (used sparingly)

0123 or 00123 or 0O123. The beginning of the 0/00/0 o

  • Hexadecimal notation

0 x3f x3f or 0. At the beginning of 0 x/x

  • Binary notation

0 bl1 or 0 bl1. At the beginning of 0 b/b


The special values are

  • Plus 0 and minus 0

They’re all equal to 0. Be careful

1 divided by 0 – > infinity 1 / + 0 – > 1 / infinity – 0 – > – infinity

  • infinity

Infinity Infinity, +Infinity, -infinity minus Infinity

  • Unexpressible number

NaN (Not a Number)

0/0->NaN(there is no way to indicate that 0 is a multiple of 0, is mathematically indeterminate, use NaN)

It is a number, even though it is unexpressible. (When the ancients counted by rope, they could not count negative numbers, such as 1-5=NaN. And then negative numbers are NaN to people at that time. But then they invented it so that 1-5 is -4.)

NaN==NaN-> get false. One indeterminate number is not equal to another indeterminate number.

64-bit floating point number

  • JS The storage form of a number

Floating point is a floating point, which means the decimal point moves around

123.456 can be represented as 1.23456e10^2

, can also be represented as 12345.6e10^-2

  • 64-bit stores a number

Symbol 1 digit Index 11 digits (-1023 to 1024) Significant digit 52 digits (the leading 1 is omitted)

Cases: (1) how to save 0.5:0.5 is converted into binary: 0.5 – > 1 * (1/2) — – > 0.1 – > 1.0 * 2 ^ (1), and 0 0-1 and figure accordingly

Cases: (1) how to save 0.625:0.625 is converted into binary: (0.5 + 0.125) > 1/2 + 1/8 — – > 1 + 1 * * (2 ^ – 1) (2 ^ – 3) – > 0.101 – > 1.01 * 2 ^ 1, then 0-1 01 and figure accordingly

JS range and precision

  • Range (ignoring sign bits)

Num_value: 1.7976931348623157e+308

When the negative direction of the index is full and the significant digit is at least 1, the minimum value is obtained: number. MIN_VALUE: 5E-324

  • Accuracy (significant number)

A maximum of 52+1 binary digits can represent significant digits.

The decimal notation for 2^53 is 9 followed by 15 zeros, so all 15 significant digits can be accurately represented. Any 16 significant digit starting with a digit less than 90 can be accurately represented. 9110000000000001 will not be saved


3. String String

Two bytes per character (castrated UTF8)

writing

Single quotes

‘hello’

Double quotation marks

“Hello”

The quotation marks

Hi ` `

  • Pay attention to

Quotes are not part of a string, just like a book name is not part of a book title. What if you want to include single quotes inside single quotes? You need to use escape characters.

escape

  • Error writing

‘it’ s ok ‘

The JS engine will think ‘it’ is over and will not understand the rest

  • Correct term

‘It’s OK’ // This is the escape

“It ‘s ok.” “

It ‘s ok `. `

  • Write it another way to say what you want

‘\’ said ‘

‘\ “said”

‘\n means newline

‘\r means enter

‘\t represents the TAB character

‘said \ \ \

‘\uFFFF represents the corresponding Unicode character

‘\xFF represents the first 256 Unicode characters

This is the text for the demonstration

Use escape: this is the _ text _ used to * demonstrate *

Multiline string

If you want to enter the string

Let s = prime

Can the

It’s easy to do with back quotes

When there are no back quotes before, you can see the netpath tutorial

String properties

Only objects have attributes, strings are special.

Search the explanation, understand the object can see.

Var a = ‘string’; , in which case it is the base type value; Var a = new String(‘ String ‘); In this case it is the object type. Primitive types have no properties or methods, but you can still use property methods that are unique to objects. This is because when the attribute method is used on a primitive type, an object of the primitive type is implicitly created in the background and then destroyed.

  • Length of string

The empty string ”.length => 0

Space string ‘ ‘.length => 1

‘\ \ \’. Length = > 3

  • The subscript of a string

Read characters by subscript

String [index]

Let s = ‘hello’;

S [0] / / “h”

Note that index starts at 0

S [0] is the first character

Notice index to length

Let s = ‘hello’;

S [4] results in ‘o’

S [5] = undefined

Base64 transcoding

  • Window.btoa (‘ What to transcode ‘)

Normal strings are converted to Base64 encoded strings, which have their own transcoding rules.

  • Window. Atob (‘ base64 content)

The Base64 encoded string is converted to the original string

Usually used to hide a resume from a job Posting

For example mailbox: MTA2OTY0NjQzNUBxcS5jb20= You can try to decode it can get my mailbox oh

  • Sometimes it’s a way to deceive yourself

The so-called “encryption”, also can fool a part of the layman

I have a code here. It’s money if you see it, but you need to decode it


4/5. Null and Undefined are two Null types

It was empty. Why are there two empty? This is the original (la) creation (JI) of JS

The difference between

There is no essential difference

  • Details a

If a variable is declared but not assigned, the default value is undefined, not null

  • Details of the second

If a function does not write return, the default return is undefined, not null

  • Details of the three

Front-end programmers, by convention, write null values for non-objects as undefined and null values for objects as null, but only by convention


6. BigInt Indicates the number type

BigInt is a built-in object that provides a way to represent integers greater than 253-1. This was originally the largest Number that could be represented as Number in Javascript. BigInt can represent an arbitrarily large integer.

Too new to check out


7. Symbol of symbols

Symbol MDN = Symbol MDN = Symbol MDN


8. Object

A brief overview and a separate update will follow

  • define

Unordered collection of data

A collection of key-value pairs

  • writing

ā‘ let obj = {‘name’: ‘frank’, ‘age’: 18}

So let me write it simple. ‘name’, ‘age’ are key names. ‘Frank ‘,’18’ is the key value (also the attribute value, each value is the attribute value of the object). Obj equals an object ({key-value pair})

ā‘”let obj = new Object({‘name’: ‘frank’})

I’ll write it formally. It’s the same thing as the first way. Let you know that this Object is constructed out of Object. Obj =nwe Objective next object

ā‘¢console.log({‘name’: ‘frank, ‘age’: 18})

Anonymous objects. Log an object without a name.

  • details

Keys are strings (as long as they are strings), not identifiers (they cannot start with a number), and can contain any character (Unicode can contain any character)

Quotation marks can be omitted, after which only identifiers can be written

You can use object.keys (obj) to view the key name of obj. You can see that the key name is still a string even if the quotes are omitted.

Strange property name

All attribute names are automatically changed to strings

let obj = {
  1: 'a'.3.2: 'b'.1e2: true.1e-2: true.234.: true.0xFF: true}; The inputObject.keys(obj)
=> ["1"."100"."255"."3.2"."0.01"."0.234"]
//1e2 = 100; //1e2 = 100
/ / 1 e - 2 = > 0.01
/ /. 234 = > 0.234
//0xff=>255
// The quotes will not change
Copy the code
  • details

Keys (obj) can get all the keys of obj, learn this API

Even weirder, variables are property names

  • How do I use variables for attribute names

We used to use constants for property names

Let p1 = ‘name’

Let obj = {p1: ‘frank’} let obj = {p1: ‘frank’} (No ‘is not a variable)

Let obj = {[p1] : ‘frank’} let obj = {[p1] : ‘frank’} ES 6 new syntax

  • contrast

Attribute names without [] are automatically changed to strings

If [] is added, it is evaluated as a variable.

A value that is not a string automatically becomes a string

Used to be

Var p1 = 'XXX' var obj={} obj[p1] = 1234 console.log(obj)Copy the code

Now it is

Var p1 = 'XXX' var obj = {[p1] :1234} console.log(obj) {XXX :1234Copy the code

Object’s hidden properties

Just a quick overview

  • Hidden attribute

Every object in JS has a hidden property

This hidden property stores the addresses of objects whose shared properties are made up of

The object made up of these common attributes is called a stereotype (more on that later)

That is, the hidden property stores the address of the stereotype

I knew there was such a thing

In addition to strings, symbols can also be property names

Let a = Symbol() let obj = {[a]: 'Hello'} Obj the key(Symbol of a) corresponds to 'Hello'Copy the code

We’ll use it when we learn about iteration








Okay, so the seven basic data types, and the five Falsy values.

If you don’t remember, go back to the top and watch it again












The decoder has eggs.

Some details of this chapter will be updated later.














This year is sure to be good, šŸ›.