当前位置:网站首页>Take you to learn more about JS basic grammar (recommended Collection)
Take you to learn more about JS basic grammar (recommended Collection)
2022-07-25 15:27:00 【꧁ small ۣۖ Pigeon ۣۖ Puzi ۣۖ ิ꧂】
Literal
Concept : Some unalterable values , Can be used directly , But generally, it will not directly make use .
for example :1 3 5 7;
Variable
Concept : Used to store literal values , And the value can be changed arbitrarily .
Statement : By keyword var Declare variables .
for example :var btn=5;
identifier
Concept :js All that can be independently named by us can become identifiers .
for example : Variable name Function name Attribute names are identifiers
Naming rules :1. It can contain letters 、 Numbers 、 Underline _、$
2. Cannot start with a number
3. Out of commission ES Keywords and reserved words in
4. It can be in Chinese
5. Hump writing is generally used
for example : Little hump helloWorld Hump HelloWorld
data type
Concept : Data types are literal types
Check data type Syntax :typeof Variable
example :var btn=”123”; console.log(typeof btn);
share Six kinds data type :
Basic types :
1.string character string
example :var str=”hello world”;
2.number The number
Concept :js All the values in are number type , Including whole Count 、 Floating point numbers ( decimal ), If the maximum value is exceeded, a Infinity It means positive infinity , Plus a minus sign is negative infinity
example :var a=123;
3.Null Null value
Concept : Specifically used to represent an empty object
Use typeof When checking, it will return object
4.undifined Undefined
Concept : When a variable is declared but not assigned a value , Its value is undefined
example :var c;
5.Boolean Boolean value true/false
Concept : Mainly used to make logical judgments -true It's true -false For false
example :var bl=false;
6. Reference type :
object object
Type conversion
Cast :
Concept : Cast one data type to another
Type conversion mainly refers to converting other data types to
String number Boolean
1. Other data types are converted to string type
Law 1 :· call toString() Method , This method does not affect the original variable , Only the converted results will be returned
null and undefined These two are not worth toString() Method
Law two : call String() function , The transformed data is passed to the function as parameters
example :
var a=123;// value type -》 String type
var b=a.toString();
console.log(typeof b);
var bl=false;// Boolean type -》 String type
var b=a.toString();
console.log(typeof b);
var c=123;
var d=string;
console.log(typeof c);//number
console.log(typeof d);//string
2. Other data types are converted to number type
Concept :
Law 1 :
character string –> Numbers
1. A pure numeric string is directly converted to a number
2. If there is non numeric content in the string, it is converted to NaN
3. If the string is empty or full space, it is converted to 0
Boolean value –> Numbers true Convert to 1,false Convert to 0
null–> The number is 0
undefined–> The number is NaN
example :var num=”123”/”123sdf1”/” ”/false/null/undefined;
var a=Number(num);
console.log(a);/123/NaN/0/0/0/NaN
Law two : Specifically used to convert string types
parseInt() You can convert strings to integers , Take out the valid integers in the string , And then convert to Number
parseFloat() You can convert a string to a floating point ( decimal ), Gets the valid decimal number in the string
example :var num=”123.23”
num=parseFloat(num);/parseInt(num);
Console.log(num);/123.23/123
3. Other data types are converted to Boolean type
Method : Use Boolean() function
1. Numbers –> Boolean except 0 and NaN yes false, Others are all true
2. character string –> Boolean Except the empty string is false, Others are all true
3.null and undefined Will be converted to false
4.object object Convert to true
example :var a=123.12;/0/NaN
a=Boolean(a);
console.log(a);/true/false/false
var str=”234fg”;/””/undefined
s=Boolean(str);
console.log(s);/true/false/false
边栏推荐
- Endnote 无法编辑range 解决
- 谷歌云盘如何关联Google Colab
- 数据系统分区设计 - 分区与二级索引
- ML - natural language processing - Introduction to natural language processing
- 期货在线开户是否安全?去哪家公司手续费最低?
- Spark SQL common time functions
- Args parameter parsing
- ML - 自然语言处理 - 关键技术
- 自定义注解校验API参数电话号
- Once spark reported an error: failed to allocate a page (67108864 bytes), try again
猜你喜欢

Simulate setinterval timer with setTimeout

Single or multiple human posture estimation using openpose

ML - 自然语言处理 - 基础知识

ML - 自然语言处理 - 关键技术

谷歌云盘如何关联Google Colab

No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac

ML - 自然语言处理 - 自然语言处理简介

wait()和sleep()的区别理解

Reflection - Notes

p4552-差分
随机推荐
How spark gets columns in dataframe --column, $, column, apply
C language function review (pass value and address [binary search], recursion [factorial, Hanoi Tower, etc.))
2019陕西省省赛K-变种Dijstra
How to solve the login problem after the 30 day experience period of visual stuido2019
Spark submission parameters -- use of files
Args parameter parsing
No tracked branch configured for branch xxx or the branch doesn‘t exist. To make your branch trac
CGO is realy Cool!
wait()和sleep()的区别理解
记一次redis超时
Promise object and macro task, micro task
Spark partition operators partitionby, coalesce, repartition
UITextField的inputView和inputAccessoryView注意点
ICPC2021昆明M-暴力+主席树
redis淘汰策列
matlab 优化工具 manopt 安装
CF566A-贪心+字典树
Spark SQL common time functions
数据系统分区设计 - 请求路由
Idea eye care settings