Home >Web Front-end >JS Tutorial >Things about global variables and local variables_Basic knowledge
Variables are very familiar to students who learn js and programming languages. I won’t elaborate on the official definition here. There are too many online. Today we will understand them from life
1. What are variables?
For example:
A water glass contains water, and the water glass is a variable;
A bottle of beer, and the beer bottle is a variable;
A variable is a carrier, a medium
2. Define variables
var a=12; //typeof a=Numer
var a='aaa' //typeof a =string
This shows the type of the variable Depends on what value is paid to him
For example, a cup filled with water is a water glass, filled with wine is a wine glass, and filled with vinegar is a vinegar bottle
3. Variable type
Variable types are divided into: basic types and reference types
Basic types are divided into: Number (numeric type), String (string type), Boolean (Boolean type), Undefined (undefined), Null
Reference types: Most of them are Objects
Basic type values are simple data stored in stack memory, and they occupy a location in memory;
Reference type values are objects stored in heap memory. What is stored in the stack memory is the address, which points to the object in the heap memory
1. Local variables