MindMap Gallery JS Basics Day5
This is a mind map about the basics of JS Day 5, including objects, extended-basic data types and reference data types, etc.
Edited at 2024-01-18 10:23:24This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about bacteria, and its main contents include: overview, morphology, types, structure, reproduction, distribution, application, and expansion. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about plant asexual reproduction, and its main contents include: concept, spore reproduction, vegetative reproduction, tissue culture, and buds. The summary is comprehensive and meticulous, suitable as review materials.
This is a mind map about the reproductive development of animals, and its main contents include: insects, frogs, birds, sexual reproduction, and asexual reproduction. The summary is comprehensive and meticulous, suitable as review materials.
JS Basics Day5
object
what is object
A data type in JSl
It can be understood as an unordered data collection. Note that an array is an ordered data collection.
Used to describe something, such as a person
People have name, age and other information
If you use multiple variables to save it, it will be more scattered, and it will be more unified if you use objects.
Object usage
Object declaration syntax
let object name = {}
let object name = new Object()
In actual development, curly braces are often used, and {} is an object literal.
Objects are composed of properties and methods
Attributes: information or features (nouns) such as mobile phone size, color, weight...
Method: Function or behavior (verb) such as making calls on a mobile phone, sending text messages...
let object name = {attribute name: attribute value, method name: function }
Attributes
Data descriptive information becomes attributes, such as a person's name, height, age, gender, etc., which are generally nominal
Attributes appear in pairs, including attribute names and values, and they are separated by English:
Use English to separate multiple attributes
Properties are variables attached to the object (variables outside, properties inside the object)
Attribute names can use "" or '', which are generally omitted unless the name encounters special symbols such as spaces, dashes, etc.
operate
Check: object.property
After declaring the object and adding several properties, it can be used. Obtaining the value corresponding to the attribute in the object is called attribute access
object['properties']
change.object.property = value
Add: object name.new attribute name = new value
Delete: delete object name.property name
methods in objects
Information about data behavior is called methods, such as running, singing, etc., which are generally verbs, and their essence is a function.
Methods are composed of two parts: method name and function. They are separated by:
Use English to separate multiple attributes
Methods are functions attached to an object
Method names can use "" or '', which are generally omitted unless the name encounters special symbols such as spaces, dashes, etc.
After declaring an object and adding several methods, you can use it to call functions in the object, which is called method calling.
You can also add formal parameters and actual parameters
Note: Parentheses need to be added after the method name.
Traverse objects
grammar
let obj = { unname: 'andy', . age: 18 } for (let k in obj) { console.log(k) console.llog(obj[k]) }
Generally, this method is not used to traverse arrays. It is mainly used to traverse objects.
The k in the for in syntax is a variable, which represents the attribute name of the object in turn during the loop.
Since k is a variable, it must be parsed using [] syntax
Be sure to remember: k is the attribute name of the object, and the object name [k] is the attribute value.
built-in objects
The object provided internally by JS contains various properties and methods for developers to call
Built-in object-Math
The Math object is a 'math' object provided by JS
Function: Provides a series of mathematical operation methods
The methods contained in the Math object
random: Generate a random number between 0-1 (including 0 but not including 1)
ceil: round up
floor: round down
max: Find the maximum number
min: Find the smallest number
pow: power operation
abs: absolute value
Math object online documentation
Extension-basic data types and reference data types
Simple types are also called basic data types or value types, and complex types are also called reference types.
Value type: simple data type/basic data type. When stored, the variable stores the value itself, so it is also called a value type.
string, number, boolean, undefined, null
Reference type: Complex data type. When storing, only the address (reference) is stored, so it is also called a reference data type. Objects (system objects, custom objects) are created through the new keyword.
Object,Array,Date