#TIL (April 28th, 열네번째 이야기)

Jung Hyun Kim·2020년 4월 28일
0

Introduction to Javascript (codecademy)

Codecademy Javascript 완성을 통해 새로운 용어 정리하기!

1. Array

1.1 .pop() Method

  • .pop() removes last item in array

1.2 .shift() Method

  • .shift() removes first item in array

1.3 .unshift() Method

  • .unshift() adds item first in array

2. Loop

2.1 for loop

  • contains three expressions separated by ; inside the parentheses:

  • an initialization starts the loop and can also be used to declare the iterator variable.

  • a stopping condition is the condition that the iterator variable is evaluated against— if the condition evaluates to true the code block will run, and if it evaluates to false the code will stop.

  • an iteration statement is used to update the iterator variable on each loop.

    
    let bobsFollowers = ['Joe', 'Marta', 'Sam', 'Erin'];
    let tinasFollowers = ['Sam', 'Marta', 'Elle'];
    let mutualFollowers = [];
    
    for (let i = 0; i < bobsFollowers.length; i++) {
      for (let j = 0; j < tinasFollowers.length; j++) {
        if (bobsFollowers[i] === tinasFollowers[j]) {
          mutualFollowers.push(bobsFollowers[i]);
        }
      }
    };
    console.log(mutualFollowers);

2.2 Do...While

  • A do...while statement creates a loop that executes a block of code once, checks if a condition is true, and then repeats the loop as long as the condition is true.
  • They are used when you want the code to always execute at least once. The loop ends when the condition evaluates to false.

2.3 Break

  • Within a loop, the break keyword may be used to exit the loop immediately, continuing execution after the loop body.

3.function

3.1 Callback function(Functions as Parameters)

모르겠음 -다시 정리 필요

4.Iterators

4.1 .forEach()

const fruits = ['mango', 'papaya', 'pineapple', 'apple'];

// Iterate over fruits below

fruits.forEach(
function(goodFruits) {
  console.log("I want to eat a "+ goodFruits);
  });

4.2 .map()

  const animals = ['Hen', 'elephant', 'llama', 'leopard', 'ostrich', 'Whale', 'octopus', 'rabbit', 'lion', 'dog'];

// Create the secretMessage array below
const secretMessage = animals.map(function(word) {
  return word[0];
}) 

console.log(secretMessage.join(''));
//

const bigNumbers = [100, 200, 300, 400, 500];

// Create the smallNumbers array below
const smallNumbers =bigNumbers.map(function(numbers) {
  return numbers/100;
})



profile
코린이 프론트엔드 개발자💻💛🤙🏼

0개의 댓글