当前位置:网站首页>First acquaintance with JS (programming suitable for beginners)
First acquaintance with JS (programming suitable for beginners)
2022-07-23 20:59:00 【Geek Yunxi】
// Ctrl+/ Double diagonal , Comment line
// Ctrl+Shift+/ Comment lines Alt+Shift+A
/*
* Variable : Identifier of data stored in computer memory , The data of the operation is operated in memory
* effect : Used to store and manipulate data
* How to use variables to store data :var Variable name = Stored data ;
* Declare variables with var
* Declaration of variables : Yes var There are variable names
* Variable initialization : Yes var There are variable names Valuable
*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
</style>
</head>
<body>
<script>
// Statement
var number;
var a, b, c, d;// Declare more than one variable at a time , No assignment
// assignment
number = 10;
console.log(number);
// Store a number 20
var num = 20;
console.log(num);// 20
// Store a name
var name = "Sherry";
console.log(name);
num = num + 10;
console.log(num);// 30
num = num + 20;
console.log(num);// 50
alert(name);// bounced Blocking process
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Exchange of variables
var num1 = 10;
var num2 = 20;
// ① Exchange with third-party variables
var temp;
// hold num1 The variables of are stored in temp in
temp = num1;// 10
// hold num2 The variables of are stored in num1 in
num1 = num2;// 20
// hold temp The variables of are stored in num2 in
num2 = temp;// 10
// ② Used to calculate
// hold num1 and num2 The sum is equal to 30, Reassign to num1
num1 = num1 + num2;// 30
num2 = num1 - num2;// 10
num1 = num1 - num2;// 20
</script>
</body>
</html>/*
* Basic code specifications :
* 1、 Every line js There should be a semicolon at the end ;
* 2、js It's case sensitive :var n = 10; var N = 10;
* 3、js You can use single quotation marks , You can also use double quotes .
*
* Specification of variable names :
* 1. Variable names must be meaningful ;
* 2. Usually in letters 、$ Symbol 、_ Start with an underline , There can be letters in the middle and after 、 Numbers 、$、 Underline , Cannot start with a number ;
* 3. The initial letter is usually lowercase , Follow the hump nomenclature : If the variable name is more than one word , First word lowercase , All the following words are capitalized var loveSherry; var yiRenZhiXia;;
* 4. It must not be a keyword or reserved name :var,let,const,new
*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// Declare multiple variables , One assignment at a time
var num1, num2, num3, num4;
num1 = 1;
num2 = 2;
num3 = 3;
num4 = 4;
console.log(num1, num2, num3, num4);
// Declare multiple variables , simultaneous assignment
var a = 10, b = 20, c = 30;
</script>
</body>
</html>/*
* The operator : Some symbols , To calculate
* Arithmetic operator :+ - * / %( Remainder )
* Arithmetic expressions : Expressions connected by arithmetic operators
* ① Unary operator : This operator only needs one operand to operate on the symbol ++ --
* ② Binary operator : Which requires two operands var num = 10 + 5;
* ③ Ternary operator : Three operands are required , When writing conditional judgment → Ternary expression
* ④ Composite operators :+= -= *= /= %=
* ⑤ Relational operator :> < >= <= ==( Not strictly equal to ) !=( Not strict is not equal to ) ===( Strictly equal to ) !==( Strict is not equal to )
* Set up return true, Not established to return false
* ⑥ Logical operators :
* && also → As long as there's an expression for false, The whole result is false One false is false
* || perhaps → As long as there's an expression for true, The real result is true True is true
* ! Take the , Take the opposite
* ⑦ Assignment operator :=
*/
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// var num = 9 / 4;
// console.log(num);// 2
// var num1 = 9 % 4;
// console.log(num1);// 1
// var num1 = 10;
// num1++;// num1 = num1 + 1
// console.log(num1);
// ++num1;
// console.log(num1);
// ++ before , First plus , Post operation
var num1 = 5;
++num1;// 6
var num2 = 6;
console.log(num1 + ++num2);// 13
// ++ After , Calculate first , After add
console.log(num1 + num2++);// 12
var num1 = 10;
num1 += 10;// amount to num1 = num1 + 10;
var num1 = 10;
var num2 = 20;
console.log(num1 > num2 && 5 < 6);// false
console.log(num1 > num2 || 5 < 6);// true
</script>
</body>
</html>
/*
* js Simple data types of :
* 1. Numeric type Number
* 2. String type String
* 3. Boolean type booleen
* 4. Null value null
* 5. Undefined undefined
* js Composite data type :
* 1. object Object
* 2. function function
* number: Numeric type ( Integers and decimals , Floating point numbers )
* string: String type ( Values are generally enclosed in single or double quotation marks )
* booleen: Boolean type ( There are only two values true/false 1/0)
* null: Empty type , It's worth only one null, When the point of an object is empty , At this point, it can be assigned null
* undefined: Undefined type , The value is just one undefined, When declaring variables , No assignment , The result is undefined
* Get the data type of the variable :typeof
* grammar :typeof Variable
example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var num = 10;
var str = "10";
var flag = true;
var $null = null;
var unde;
var obj = new Object();
var f1 = function() {
}
console.log(typeof num);// number
console.log(typeof str);// string
console.log(typeof flag);// boolean
console.log(typeof $null);// object
console.log(typeof unde);// undefined
console.log(typeof obj);// object
console.log(typeof f1);// function
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
// One 、Number type : Integers and floating point numbers ( decimal )
// var num1 = 10;
// var num2 = 10.33;// Floating point numbers
// Two 、 Range of numeric types : Maximum and minimum
// console.log(Number.MAX_VALUE);// Maximum 1.7976931348623157e+308
// console.log(Number.MIN_VALUE);// minimum value 5e-324 5 multiply 10 Of -324 Power
// infinity :Infinity
// An infinitesimal :-Infinity
// 3、 ... and 、 Don't judge that two floating-point numbers are equal
// var x = 0.1;
// var y = 0.2;
// console.log(x + y);// 0.3? It didn't turn out to be 0.3, It is 0.30000000000000004
// console.log(0.07 * 100);// No 7, It is 7.000000000000001
// Four 、 Numerical judgment
var num;
console.log(num + 10);// NaN → not a number
// NaN Not equal to any value , Including himself
// Do not use NaN verification NaN
// = assignment == be equal to
console.log(num + 10 == NaN);// false
// How to verify whether the result is NaN, Use isNaN( Variable name )
// isNaN → is not a number
console.log(isNaN(num));// true → No number
var num2 = 100;
console.log(isNaN(num2));// false → yes number
</script>
</body>
</html>01.Number type
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var str1 = "abc";
var str2 = "Sherry";
var str3 = "hello word!"
// String length : Variable name .length
console.log(str1.length);// 3
console.log(str2.length);// 6
console.log(str3.length);// 11
// Escape character
// \n Line break \t Tabulation \b Space \r enter \\ Slash \ \" Double quotes \' Single quotation marks
// String splicing use + link
console.log(11 + 11);// 22
console.log("11" + 11);// 1111
console.log("hello" + "word");// helloword
console.log("sss" + true);// ssstrue
// 1. Just one string on either side , that + It's string concatenation
// 2. If both sides are numbers , that + It's the arithmetic function
</script>
</body>
</html>边栏推荐
- [cloud co creation] what magical features have you encountered when writing SQL every day?
- 高数下|三重积分的计算1|高数叔|手写笔记
- Himawari-8 数据介绍及下载方法
- Today's sleep quality record 81 points
- 确定括号序列中的一些位置
- [Yunxiang book club No. 13] Chapter V ffmpeg common methods for viewing media information and processing audio and video files
- MySQL(3)
- OOM机制
- 现在完全不知道怎么同步
- 信号的理解
猜你喜欢

Go to the square for dinner

Car rental vehicle management system based on jsp+ssm+mysql car rental

实现生成订单30分钟未支付,则自动取消

《迷失》stray工人帽子获得方法 工人安全帽在哪里?
![[shader realizes roundwave circular ripple effect _shader effect Chapter 6]](/img/3f/90c2f0004303dc577eba1615fa3fd7.png)
[shader realizes roundwave circular ripple effect _shader effect Chapter 6]

The third slam Technology Forum - Professor wuyihong

LU_ Asr01 voice module usage
![[kernel] platform bus model for driving development and learning](/img/69/f600e4e6173491955ab90e92577450.png)
[kernel] platform bus model for driving development and learning

Leetcode hot topic hot52-100

Chapter 3 business function development (creating clues)
随机推荐
最小生成树:Kruskal
Day 11: continue the basic configuration of BGP for day 10
Trial record of ModelBox end cloud collaborative AI development kit (rk3568) (II)
高数下|三重积分的计算1|高数叔|手写笔记
信号的理解
prime_series_level-1
Network learning infrared module, 8-way emission independent control
Himawari-8 data introduction and download method
Leetcode hot topic hot52-100
LeetCode热题 HOT52-100
Jetson nano recording stepping on the pit (it will definitely solve your problem)
TypeScript基础
HDU - 2586 How far away ? (multiply LCA)
STM32c8t6驱动激光雷达(一)
LU_ Asr01 voice module usage
Understanding of signals
ssm+mysql实现零食商城系统(电商购物)
Connect with Hunan Ca and use U_ Key login
【isprint函数判断字符是否可输出】
win7-vs2012下安装.net frame work 的过程图文详解