Day 15/2

Plan 15/2:

  • 8h-15h: learning/practicing Js

  • 15h~ : customize speed

Javascript

1. classList

  • .classList.add('newClass'): add a new class to the target

  • .classList.remove('newClass'): remove a class from the target

  • .classList.contains('className'): check if the target has a specific class

2. Array

Array is a special Object

const myArray = [1, 2, 3, 'hello', {name: 'ball';}, [3, 2, 1]];

myArray[0] = 1;

Cause it is an Object, it also has methods and properties

  • .length: array 's length

  • .push(): push an item to the end of the array

  • .splice(x, y): remove y items from position x

When creating an array, it creates a reference to the actual data in memory.

array1 = [1, 2, 3];

array2 = array1;

array3 = array1.slice();

array1 and array2 point to the same data in memory, 1 array change make the other change

array3 make a copy of the data, any change is individual

3. Loops

Run the code inside as long as the condition is true. Loops create a scope.

  • while loop: used with non-standard loop which means loop with no jumping step, more flexible

while (condition) { }

  • for loop: used with standard loop which have steps

for (let i = a; i <= b; i++) { }

Last updated