Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JavaScript variables and data types


May 28, 2021 Article blog


Table of contents


JavaScript is no stranger, so are JavaScript variables and data types deep enough?

variable

1, declare variables before assigning values

var width;
width = 9;

var: Is the keyword used to declare variables

width: Assigns a value to the variable name

2, declare and assign variables at the same time

var catName= "小明";
var x, y, z = 10;

3, do not declare direct assignment (rarely used)

width = 5;

Here variables can be used directly without declaration, but more error-prone, not easy to find and exclude errors, not recommended for everyone to use.

data type

1、undefined

Example: var width

The variable width has no initial value and is assigned a value of undefined

2、null

Represents an empty value equal to undefined

3、number

Var num=23 // This is an integer

Var num=23.0 // This is the floating point

4、Boolean

true and false but JS resolves to 1 or 0

5、String

Text enclosed in single or double quotes

var string = "This is a string"

That's all you need to do with JavaScript variables and data types.