Daily Report
  • Day 1 - 22/8
  • Day 2 - 23/8
  • Day 3 - 24/8
  • Day 4 - 25/8
  • Day 5 - 26/8
  • Day 6 - 28/8
  • Day 7 - 29/8
  • Day 8 - 30/8
  • Day 9 - 4/9
  • Day 10 - 5/9
  • Day 11 - 6/9
  • Day 12 - 7/9
  • Day 13 - 8/9
  • Day 14 - 9/9
  • Day 15 - 11/9
  • Day 16 - 12/9
  • Day 17 - 14/9
  • Day 18 - 15/9
  • Day 19 - 18/9
  • Day 20 - 19/9
  • Day 21 - 20/9
  • Day 22 - 21/9
  • Day 23 - 22/9
  • Day 24 - 23/9
  • Day 25 - 25/9
  • Day 26 - 26/9
  • Day 27 - 27/9
  • Day 28 - 28/9
  • Day 29 - 29/9
  • Day 30 - 2/10
  • Day 31 - 3/10
  • Day 33 - 7/10
  • Day 32 - 4/10
  • Day 34 - 9/10
  • Day 35 - 10/10
  • Day 36 - 11/10
  • Day 37 - 16/10
  • Day 38 - 17/10
  • Day 39 - 18/10
  • Day 40 - 19/10
  • Day 41 - 20/10
  • Day 42 - 21/10
  • Day 43 - 23/10
  • Day 44 - 25/10
  • Day 45 - 26/10
  • Day 46 - 27/10
  • Day 47 - 30/10
  • Day 48 - 31/10
  • Day 49 - 1/11
  • Day 50 - 2/11
  • Day 51 - 3/11
  • Day 52 - 5/11
  • Day 53 - 6/11
  • Day 54 - 7/11
  • Day 55 - 8/11
  • Day 56 - 9/11
  • Day 57 - 10/11
  • Day 58 - 13/11
  • Day 59 - 14/11
  • Day 60 - 15/11
  • Day 61 - 16/11
  • Day 4/12
  • Day 6/12
  • Day 7/12
  • Day 8/12
  • Day 12/12
  • Day 13/12
  • Day 14/12
  • Day 15/12
  • Day 16/12
  • Day 18/12
  • Day 19/12
  • Day 20/12
  • Day 21/12
  • Day 25/12
  • Day 26/12
  • Day 27/12
  • Day 28/12
  • Day 29/12
  • Day 3/1
  • Day 4/1
  • Day 5/1
  • Day 8/1
  • Day 10/1
  • Day 11/1
  • Day 12/1
  • Day 13/1
  • Day 15/1
  • Day 16/1
  • Day 17/1
  • Day 18/1
  • Day 19/1
  • Day 23/1
  • Day 24/1
  • Day 27/1
  • Day 29/1
  • Day 30/1
  • Day 1/2
  • Day 2/2
  • Day 5/2
  • Day 6/2
  • Day 15/2
  • Day 16/2
  • Day 17/2
  • Day 19/2
  • Day 20/1
  • Day 21/2
  • Day 22/2
  • Day 23/2
  • Day 26/2
  • Day 27/2
  • Day 28/2
  • Day 29/2
  • Day 1/3
  • Day 4/3
  • Day 5/3
  • Day 6/3
  • Day 7/3
  • Day 8/3
  • Day 9/3
  • Day 11/3
Powered by GitBook
On this page
  • Data types:
  • Function
  • Objects
  • Events
  • String
  • String method
  • String search
  • Numbers
  • Number Method

Day 34 - 9/10

Plan: Continue learning JavaScript

Progress:

Data types:

  • Js types are dynamic, which means the same var can have different data types

  • when add number and string, the number will be treated as string; caculation still be done if there is no string before that

  • array: const name = [a, b, c];

  • objects: const name = {a, b, c}; : works like struct

  • undefined: a var without value hold value undefined and type undefined; string without value hold value "" and type undefined

Function

  • function name(parameter1, parameter2, parameter3) { // code to be executed }

  • Accessing a function without () returns the whole function, not the result: let value = toCelsius;

  • Functions can be used the same way as variables, in all types of formulas, assignments, and calculations.

Objects

  • const name = {property:property name, ... }

  • A method is a function stored as a property.

  • this keyword

  • do not declare Strings, numbers, and booleans as object

Events

  • Js event is how Js react when sth happen to Html elements (click a button, web page finished loading, ...)

  • event are commonly used in function rather than directly used

String

  • let string = string.length;

  • turn special characters to string: \' ~ ' ; \" ~ "

String method

Extract string parts:

  • slice(start, end); :

    • if 'end' is omitted, the method will slice out from 'start' to the rest

    • if 'end' is omitted, 'start' is negative, the position will be counted from the end

    • 'end' and 'start' is negative works like positive

  • substring(start, end); : works as slice but negative values are treated as 0

  • substr(start, length); similar to slice

Replace string

let text = "Please visit Microsoft!"; let newText = text.replace("Microsoft", "W3Schools");

  • replaces a specified value with another value in a string; returns a new string, does not change the string it is called on; and only replace the first match; case sensitive

  • use /specified value/i flag to remove case sensitive

  • use /specified value/g flag to replace all matches

  • text = text.replaceAll("Cats","Dogs");

Uppercase / Lowercase

  • toUpperCase() : the whole string to uppercase

  • toLowerCase() ; the whole string to lower case

Concat

  • join 2 or more string

let text3 = text1.concat(" ", text2);

Trim

  • remove whitespace from head and tail

  • trimStart() / trimEnd() : remove whitespace from head or tail only

String padding

  • padStart() / padEnd(): pad head or tail with character "y" until reach length x

let padded = text.padStart(x,"y");

  • to padding number, it needed to convert to string first

let numb = 5;

let text = numb.toString();

let padded = text.padStart(4,"0");

Extracting characters

  • charAt(position) : return the character

  • charCodeAt(position) : return the UTF-16 code of the character

String search

  • indexOf() return the first position of a string in a string; search forward

  • lastIndexOf() return the last position of a string in a string; search backward

  • Both indexOf(), and lastIndexOf() return -1 if the text is not found

  • a second parameter is added to declare the position to start searching:

text.lastIndexOf("locate", 15);

  • search()

String match

  • .match("string"); : returns an array containing the results of matching a string against a string

  • .match(/ain/gi); : use /g , /i flag to find all matches despite uppercase or lowercase

  • .matchAll() : return every matches in order

  • .includes("specified value", position) : return true / false whether the value is included or not, search from position forward (optional); case sensitive

  • .startsWith() : return True / false; check if the string starts with specified value or not; a second parameter to set the start position (optional); case sensitive

  • .endsWith()

Numbers

Integer Precision

  • Integers (numbers without a period or exponent notation) are accurate up to 15 digits

Floating Precision

  • Floating point arithmetic is not always 100% accurate; to solve this, multiply the parameter, calculate then divide

Not a Number

  • do arithmetic with a non-numeric string result in NaN

  • isNaN() check a value is or isn't a number

  • typeof NaN is number

Infinity (or -Infinity)

  • the value return when calculate a number outside the largest possible number

  • Infinity is a number

Hexadecimal

  • hexadecimal constant preceded by 0x

  • .toString() : to convert number among bases (base 2, base 10, base 8, ...)

Numbers as Objects

  • numbers can be defined as objects but DON'T

  • objects can't be compared with objects

  • compare 2 objects alway return false

Number Method

  • .toString() : convert number to string

  • .toExponential(x) : rounded number to x numbers behind decimal point

  • .toFixed(x) : number of decimal

  • .toPrecision(x) : number with length x

  • .valueOf() : return a number as a number

  • Number() : convert JavaScript variables to numbers

  • parseInt() : parse a string and return the first number, float not included

  • parseFloat() : parse a string and return the first number

PreviousDay 32 - 4/10NextDay 35 - 10/10

Last updated 1 year ago