Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the time objects and reference types of JS

Shulou Source: shulou.com Published: 2022-06-01 05:49:00 09月25日 Update

This article mainly explains "what is the time object and citation type of JS". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the time object and citation type of JS".

Basic types: String type, Null type, Number type, Undefined type, Boolean type

Complex types: Object typ

Function:

String type: String is a sequence of Unicode characters, commonly known as a string, which can be expressed in double quotation marks or single quotation marks. There is no difference, just match.

Null type: the Null type has only one value: null, which represents a null pointer, that is, something that does not exist

Number type: the number type of JavaScript is different from other languages. There is no difference between integer and floating point numbers. All of them are Number types, which can represent decimal, octal and hexadecimal.

Undefined type: the Undefined type also has only one value, undefined, which means that the variable is only declared and not initialized, that is, there is a pointer, but the pointer does not point to any space.

Boolean type: Boolean has two values: 1.true2.false

Object types: objects (object) are the core concept of JavaScript and the most important data type. All the data in JavaScript can be regarded as objects, which is what we often say that everything is objects.

The output of the following code? Why?

Varobj1= {a:1,b:2}

Varobj2= {a:1,b:2}

Console.log (obj1==obj2); / / false, because obj1 and obj2 are stored in different locations, so false.

Console.log (obj1=obj2); / / obj2 assigns a value to obj1 to output the content of Object {axi1jib 2}.

Console.log (obj1==obj2); / / assign obj2 to obj1, so obj2 is stored in the same location as obj1, so it is true.

Code

Write a function getIntv to get the interval from the current time to the specified date.

Varstr=getIntv ("2016-01-08")

Console.log (str); / / 20 days, 15 hours, 20 minutes and 10 seconds from New Year's Eve

Code:

Varstr=getIntv ("2017-01-27")

FunctiongetIntv (time) {

Varend=newDate (time)

Varnow=newDate ()

Vartimer=end-now

Varday=Math.floor (timer/ (1000606024))

Vartimer1=timer% (1000606024)

Varhour=Math.floor (timer1/ (10006060))

Vartimer2=timer1% (10006060)

Varmin=Math.floor (timer2/ (100060))

Vartimer3=timer2% (100060)

Varsec=Math.floor (timer3/1000)

Return ("distance" + time+ "and" + day+ "days" + hour+ "hours" + min+ "minutes" + sec+ "seconds")

}

Console.log (str); / / 20 days, 15 hours, 20 minutes and 10 seconds from 2017-01-27

Change a numeric date to a Chinese date, such as:

Varstr=getChsDate ('2015-01-08')

Console.log (str); / / January 8, 2015

Code:

Method 1:

Varstr=getChsDate ('2015-01-08')

FunctiongetChsDate (time) {

Time=time.replace (/-/ gjinghui')

Vararr= []

For (iSuppli)

Tags: Type object code time method character number eight days string copy array date output content hour Boolean pointer learning difference that is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn Shulou Tech Info Shulou Information OPPO Reno