SoFunction
Updated on 2025-04-05

What are the specific basic data types in JS development

What are the basic data types in JS development? JS data types include basic data types, complex data types and special data types. Today we will mainly explain basic data types.

0. First, please remind two of the following knowledge points:

0.1typeof is used to detect variable types

Writing: typeof a;

0.() is used to print the parts you need in the console

Generally, after entering the HTML file page, right-click to select Check, the console will appear. Select console to see what you have printed.

In addition: alert() is the page pop-up box to display content

() is the way to output content in the page

1. Variables: Before talking about basic data types, let’s first understand the method of defining variables in JS.

1.1 Defining variables: When defining a variable, you can give the initial value of the variable without distinguishing between types (types of containers).

1.2 Naming specifications for variables: combinations of letters, numbers, underscores and $; cannot start with numbers; cannot be keywords and reserved words; camel nomenclature.

1.3 The initial value can only be the following 5 types:

Number type, number can only be a number or a decimal

var a = 10;
(typeof a);//number
var b = 10.6;
(typeof b);//number

String type String, any character wrapped in single or double quotes

var c = 'hello';
(typeof c);//string
var d = "world";
(typeof d);//string

Boolean type Boolean can only be true or false to represent true or false

var e = true;
(typeof e);//boolean
var f = false;
(typeof f);//boolean

Undefined, no value is assigned after defining the variable. This variable is undefined

var g;
(typeof g);//undefined

Empty null is an object type. There are many types of object types, such as array objects, mathematical objects, and date objects (latest learning)

var h = "";
(typeof h);//null

And these five are the five basic data types of JS.

2. Type conversion

Conversion of numeric types, string types and boolean types

2.1 Turn value—Number()

(Number("123"));//123
(Number("12.3"));//12.3
(Number("12hshs"));//NaN
(Number('0034'));//34
(Number(""));//0
(Number(true));//1
(Number(false));//0
(Number(null));//0
(Number(undefined));//NaN

Note: NaN: not a number, others will be explained later

2.2 Turn the string String(), what to write to what to turn

(String(123));//123
(String(0));//0
(String(true));//true
(String(false));//false
(String(undefined));//undefined
(String(null));//null

2.3 to Boolean()

Skill:

Number to boolean is not 0 to true

String to boolean is not empty to true

NaN null undefined to convert string to false

(Boolean("123"));//true
(Boolean("0"));//true
(Boolean("Shandong"));//true
(Boolean(""));//false
(Boolean("true"));//true
(Boolean("false"));//true
(Boolean(14));//true
(Boolean(0));//false
(Boolean(NaN));//false
(Boolean(-100));//true
(Boolean(undefined));//false
(Boolean(null));//false

Summarize

The above is what are the basic data types in JS development introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!