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
  • Bitwise
  • Regular Expressions
  • Error
  • Scope
  • Hoisting
  • Strict mode
  • this Keyword
  • Arrow function
  • Class

Day 37 - 16/10

Plan:

Morning - 15h30: Learning Js: Bit wise, Regular expression, Precedence, Error, Scope, Hoisting, Strict mode, this Keyword, Arrow function, Class

>15h30: Converting web to html:

Progress:

Bitwise

  • Js uses 32 bits bitwise operands

  • Decimal to Binary

function dec2bin(dec){

return (dec >>> 0).toString(2);

}

dec >>> 0 : doesn't shift the number, just convert the dec value to number and set the sign bit to 0 (always positive)

  • Binary to Decimal

function bin2dec(bin){

return parseInt(bin, 2).toString(10);

}

Regular Expressions

.search(" "); : return first position

.match(" "); : return every matches posible

.replace("one", "other"); : consecutively replace words "one" with word "other" each time activate

pattern.test("string"); : check if string contains pattern

pattern.exec("string"); : search for the first pattern matches in string and return it as object

A regular expression is a sequence of characters that forms a search pattern.

  • / /i : case-insensitive matching

  • / /g : global match (find all matches)

  • / /m : multiline matching

  • [abc] : Find any of the characters between the brackets (case-sensitive)

  • [0-9] : Find any of the digits between the brackets

  • (x|y) : Find any of the word or letter

  • \d : Find a digit

  • \s : Find a whitespace

  • \b : Find a match starts with WORD ( \bWORD ), or ends with WORD ( WORD\b )

  • \uxxxx : Find the Unicode character specified by the hexadecimal number xxxx

  • n+ : Matches any string that contains at least one n

  • n* : Matches any string that contains or not contains n

  • n? : Matches any string that contains zero or one n

Error

  • try {} : define a code block to run

  • catch(err) {} : define a code block to handle any error

  • finally {} : define a code block to run regardless of the result

  • throw {} : define a custom error

Use "try" and "catch" in pair

Error Object properties

  • name : set or return an error name

  • message : set or return an error message

Error Name value

  • RangeError : A number "out of range" has occurred

  • ReferenceError : An illegal reference has occurred

  • SyntaxError : A syntax error has occurred

  • TypeError : A type error has occurred

  • URIError : An error in encodeURI() has occurred

Scope

In JavaScript, objects and functions are also variables.

Types:

  • block scope: provided when "let" or "const" is used inside a block. "var" doesn't have block scope

  • function scope: each function creates a new scope, variables can not be accessed from outside

  • global scope: a variable declared outside a function become global; can be accessed by all script and function on the web page

When assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable

Lifetime of Js variables

  • start when it is declared

  • local var are deleted when the function completed

  • in web browser, global var deleted when close browser window

Hoisting

Means a variable can be used before be declared

Only "var" has hoisting

Strict mode

"use strict"

Help writing cleaner code, preventing from using undeclared variables.

Not allowed:

  • Using a variable (or object) without declaring

  • Deleting a variable (or object), a function, an undeletable property

  • Duplicating a parameter name

  • Writing to a read-only (or get-only) property

  • ...

this Keyword

this refer to:

  • the object when used in an object method

  • the global object when used alone ( in a browser window the global object is [object Window])

  • the global object when used in a function

  • undefined when used in a function in strict mode

  • the element that receive the event in event handler

  • .call() and .apply() method can be used to call an object method with another object as argument

  • .bind() method is for an object to borrow a method from another object

Arrow function

Allow us to write shorter function syntax

From

hello = function() { return "Hello World!"; }

to

hello = () => { return "Hello World!"; }

to ( if function only have 1 statement )

hello = () => "Hello World!";

( if function has parameters)

hello = (val) => "Hello " + val;

to ( if there is only 1 parameter )

hello = val => "Hello " + val;

In Arrow function, this keyword represents the object owns the function no matter who calls the function

Class

class ClassName {

constructor(element1, element2, ...) {

this.element1 = x;

this.element2 = y;

...

}

method1() { }

method2() { }

}

  • Class is not an object. It's a template for objects

  • Can use class to create objects:

const elementN = new ClassName("Ford", 2014);

PreviousDay 36 - 11/10NextDay 38 - 17/10

Last updated 1 year ago