# JavaScript 入门 Day2

By [aow](https://paragraph.com/@ashonthewall) · 2022-03-09

---

第二天，还是比较简单的基础知识，先学后教，记得牢，不费力，冲！

**11 Add Two Numbers with JavaScript**

**12 Subtract One Number from Another with JavaScript**

**13 Multiply Two Numbers with JavaScript**

**14 Divide One Number by Another with JavaScript**

来到Number这个data type。

这个很好理解，就是数字。

const a = 1;

const b = 1;

a + b = 2;

简直太简单了吧。

加减乘除一样的，都放一起了。

**15 Increment a Number with JavaScript**

**16 Decrement a Number with JavaScript**

每次递增1怎么弄？

a = a + 1;

每执行一次都+1。

更简单的形式

a++;

两个一样的，下面更顺手。

减法也是一样的，

a--;

// 这种形式只适用于加减1哦。

**17 Create Decimal Numbers with JavaScript**

**18 Multiply Two Decimals with JavaScript**

**19 Divide One Decimal by Another with JavaScript**

number当然也可以有小数点。

const a = 1.5;

const b = 4.5;

然后加减乘除。

a \* b;

a / b;

// 这几关简直太水了😂。

**20 Finding a Remainder in JavaScript**

一个新符号，

%

余数的意思。

仍然是中国小学三年级就已经学过的水平😂。

const remainder = 11 % 3;

猜猜remainder这个框里装的东西是啥？

对，是2。

/ \* 写到这里，我发现mirror可以用code格式。。

那接下去code部分就用code了 😊 \*/

**21 Compound Assignment With Augmented Addition**

**22 Compound Assignment With Augmented Subtraction**

**23 Compound Assignment With Augmented Multiplication**

**24 Compound Assignment With Augmented Division**

参考练习15 16啊，一样的，无非是1变成了任意数字。

// 太水了，这几关。。

**25 Escaping Literal Quotes in Strings**

还记得string这种data type两边要加上 “ " 吗？

如果这个string variable盒子里装的东西自带 “ ” 咋办？计算机如何分辨？

    const quote = "Alan said, \" Peter is learning JS\".";
    

这行代码输出的结果是

    Alan said, "Peter is learning JS".
    

通过 \\" 这个符号组合，计算机会自动把引号认做字符，而不是string的标识。

// 这里要注意 /和\\的区别，一个叫forward slash, 一个叫back slash.

![](https://storage.googleapis.com/papyrus_images/48ff56b37f21ccc902824f6bc79a13c1ef5acdd5a8cd198d58cf42e935993edd.png)

**26 Quoting Strings with Single Quotes**

除了用 \\” ，也可以把外双引号换成单引号。

**27 Escape Sequences in Strings**

\\ 除了标注引号，还有很多用途。

`\'`single quote

`\"`double quote

`\\`backslash

`\n`newline

`\r`carriage return

`\t`tab

`\b`word boundary

`\f`form feed

怎么按照格式输出这行字

FirstLine     \\SecondLine ThirdLine

大家做完这个练习就能掌握\\的大部分用途了。

**28 Concatenating Strings with Plus Operator**

strings 也可以拼接起来，用 +， 和number一样。

    const ourStr = "I come first. " + "I come second.";
    

输出结果

I come first. I come second.

很好理解吧？

有一点要注意，如果两句话想要有个空格，空格加在第二个I之前。

**29 Concatenating Strings with the Plus Equals Operator**

和number一样的逻辑，string也可以用 += 来添加。

**30 Constructing Strings with Variables**

和number, string一样，+ 对variable也适用。

**31 Appending Variables to Strings**

好的，+= 对string, number, variables 全部适用😂。

Day2依然是最基础的内容，依然可以划水。

虽然内容简单，但概念越基础越重要，我们小白更应该掌握扎实，以后学起来就轻松。

好了，才两天，就已经完成31个练习了，完成了我们基础课程的接近1/4！胜利指日可待了。

明天见！

**_btw，在这两个discord频道都可以找到我_**

[https://discord.gg/madnfts](https://discord.gg/madnfts)

[https://discord.gg/Z25p8gkZWx](https://discord.gg/Z25p8gkZWx)

---

*Originally published on [aow](https://paragraph.com/@ashonthewall/javascript-day2)*
