Basic JavaScript 030

01-Comment your JavaScript Code

// inline comment

/**
  * block comment
  *
  *
  */

02-Declare JavaScript Variables

  • 宣告變數

  • 可以直接從七種資料型態宣告

  • 操作指向數據的指針,而不是資料表身

  • 或直接使用 var

// Example
var ourName;
var myName;
// Define myName below this line

03-Storing Values with the Assignment Operator

// Setup
var a;
var b = 2;

// Only change code below this line
a = 7;
b = a;

04-Initializing Variables with the Assignment Operator

  • 使用 = 給變數一個初始值

05-Understanding Uninitialized Variables

  • 只有宣告變數的話,初始值為 undefined

  • 如果對 undefined 變數做數學運算,結果會是 NaN,代表 not a number

06-Understanding Case Sensitivity in Variables

  • JS 的變數對大小寫敏感

  • 但不要使用這個特性,會搞混

  • 推薦駝峰命名法 camelCase

  • 變數的第一個字母小寫,隨後單字的第一個字母大寫

07-Add Two Numbers with JavaScript

08-Subtract One Number from Another with JavaScript

09-Multiply Two Numbers with JavaScript

10-Divide One Number by Another with JavaScript

11-Increment a Number with JavaScript

  • i++

12-Decrement a Number with JavaScript

  • i--

13-Create Decimal Numbers with JavaScript

14-Multiply Two Decimals with JavaScript

15-Divide one Decimal by Another with JavaScript

16-Finding a Remainder in JavaScript

Example 5 % 2 = 1 because Math.floor(5 / 2) = 2 (Quotient) 2 * 2 = 4 5 - 4 = 1 (Remainder)

17-Compound Assignment With Augmented Addition

18-Compound Assignment With Augmented Subtraction

19-Compound Assignment With Augmented Multiplication

20-Compound Assignment With Augmented Division

21-Convert Celsius to Fahrenheit

22-Declare String Variables

23-Escaping Literal Quotes in Strings

24-Quoting Strings with Single Quotes

  • 這功能好神奇,這樣不需要 back slash、反斜杠來跳脫字元了

25-Escape Sequences in Strings

  • 超詭異的用法 ==

26-Concatenating Strings with Plus Operator

27-Concatenating Strings with the Plus Equals Operator

28-Constructing Strings with Variables

29-Appending Variables to Strings

30-Find the Length of a String

Last updated

Was this helpful?