How many types of JS are there
The current ECMAScript standard defines seven data types:
All data types, with the exception of Object, define unchangeable values (values that cannot be changed). For example, unlike C, strings are immutable. The values of these data types are called "primitive values".
Boolean data type
Boolean represents a logical unit and can have two values: and.
Null data type
The null type has exactly one value:. See and zero for more details.
Undefined data type
A variable that has not yet been assigned a value has the value. See and Undefined for more details.
Number data type
According to the ECMAScript standard there is only one data type for numbers: double-precision 64-bit binary format IEEE 754 value (numbers between - (263) and +263-1). There is no specific data type for integers. In addition to floating point numbers, the data type for numbers can also have three symbolic values:, and (not-a-number = no number).
The data type for numbers has an integer with two representations: 0 can be represented as -0 and +0. ("0" is an alias for +0). In practice this has almost no effect. Is for example . However, a division gives two different values:
String data type
- A substring of the original string by selecting certain characters or using the method.
- A concatenation of two strings with the operator () or.
Avoid "stringly-typing" in your code!
String can be tempting to represent complex data. It has short-term benefits:
- Complex strings can be created simply by concatenation.
- Strings are easier to debug (the output corresponds to the content of the string).
- Strings are used in many APIs (input fields, local storage values, responses in their capacity as, etc.). This can make it tempting to work with strings only.
Strings should only be used for textual data. If you want to represent complex data, parse the string and use an appropriate abstraction.
Symbol data type
In computer science, objects are values in memory that may be referenced using an identifier.
There are two types of properties that have certain attributes: the data properties and access properties.
Associates a key with a value and has the following attributes:
|attribute||Data type||description||default value|
|[[Writable]]||Boolean||if [[Value]] of the property cannot be changed.||false|
|[[Enumerable]]||Boolean||if the property in for ... is listed in loops. See also enumerability and ownership of properties.||false|
|[[Configurable]]||Boolean||if the property cannot be deleted and the attributes [[Value]] and [[Writable]] cannot be changed.||false|
Associates a key with one or two accessor functions (get and set) to obtain or store a value. It has the following attributes:
|attribute||Data type||description||default value|
|[[Get]]||Function object or undefined||The function is called without an argument and returns the value of the property as soon as a get access is performed on the value. See also get (en-US).||undefined|
|[[Set]]||Function object or undefined||The function is called with an argument that contains the value for the assignment. It is always called as soon as a certain property is to be changed. See also set (en-US).||undefined|
|[[Enumerable]]||Boolean||if the property in for ... is listed in loops.||false|
|[[Configurable]]||Boolean||if the property cannot be deleted and changed to a data property.||false|
"Normal" objects and functions
Functions are regular objects with the ability to be called directly.
Indexed Collections: Arrays and Typed Arrays
Arrays are regular objects in which there is a relationship between properties, which are indexed via integers, and the property 'length'. In addition, arrays inherit from, a helper method that offers manipulation of arrays, such as (to find a value in an array) or (to add elements to an array). This allows lists and quantities to be represented via an array.
|Type||Value range||Size in bytes||Description||Web IDL type||Equivalent C type|
|to||1||8-bit two's complement signed integer|
|to||1||8-bit unsigned integer|
|to||1||8-bit unsigned integer (clamped)|
|to||2||16-bit two's complement signed integer|
|to||2||16-bit unsigned integer|
|to||4||32-bit two's complement signed integer|
|to||4||32-bit unsigned integer|
|to||4||32-bit IEEE floating point number (7 significant digits e.g.,)|
|to||8||64-bit IEEE floating point number (16 significant digits e.g.,)|
|to||8||64-bit two's complement signed integer|
|to||8||64-bit unsigned integer|
Keyed Collections: Maps, Sets, WeakMaps, WeakSets
These data structures use object references as keys. They were introduced with ECMAScript Edition 6. and represent a set of objects, while and associate a value with an object. The difference between Maps and WeakMaps is that maps can be iterated over object keys. This allows a later optimization of the garbage collection.
Maps and sets could be implemented in pure ECMAScript 5. However, since objects cannot be compared (in the sense of, for example, "less than or equal to"), the performance for a look-up would be linear. Native implementations (including weak maps) can have an approximately logarithmic look-up performance.
To bind data to a DOM node, the properties are usually set directly on the object or attributes are used. However, this has the disadvantage that the data is available in the same context for each script. With Maps and WeakMaps, data can easily be linked privately to an object.
Structured data: JSON
More objects in the standard library
Determine data types with the operator
The operator can find out the data type of a variable. More details and borderline cases can be found on the reference page.
- Is GTA V online DLC free
- Who are the best chefs in Caracas
- How is vowel vibrato created
- Which restaurant delivery service accepts cash?
- Why do different reactions require different catalysts
- Why does the world even exist
- What is a robotic hair transplant
- Why is my fish dead
- How far is Istanbul from Cappadocia
- Is Olay Creme a good day cream
- Where we can find Indians in Russia
- What are the facts about Brett Kavanaugh
- How can we hire interns in Bangalore
- Why do you think God made sex?
- What to do for the IAS preparation
- In relation to international travel
- Can a heavy powerlifter run a marathon
- What will be the solution for 64?
- What is your experience with AWS support?
- What are the advantages of Turbo C.
- How can I treat my ankle pain
- Is the electronics and instruments area tough
- Can Apache Beam replace Apache Spark
- Homeschoolers can receive funding for their education