본문 바로가기

Udemy/Web Dev BootCamp

Advanced Array Method Recap forEach: iterates over an array, runs a callback on each value and returns undefined map: creates a new array, runs a callback on each value and pushes the result of each callback in the new array filter: creates a new array, runs a callback on each value and if the result of the callback returns true, that value is added to the new array some: iterates through an array and runs a callback on ea..
Advanced Array Methods(reduce) reduce : Accepts a callback function and an optional second parameter Iterates through an array Runs a callback on each value in the array The first parameter to the callback is either the first value in the array or the optional second parameter The first parameter to the callback is often called "accumulator" The returned value from the callback becomes the new value of accumulatorWhatever is ..
Advanced Array Methods(some & every) some: Iterates through an array Runs a callback on each value in the array If the callback returns true for at least one single value, return true Otherwise, return falseThe result of the callback will ALWAYS be a boolean function some(array, callback){for (var i = 0; i return num.toString().split('').some(function(val){ return val[key] === 0; > return val === "0"; });} /*Write a function called..
Advanced Array Methods(filter) filter: Creates a new array Iterates through an array Runs a callback function on each value in the array If the callback function returns true, that value will be added to the new array If the callback function returns false, that value will be ignored from the new array function filter(array, callback){var newArr = [];for(var i = 0; i < array.length; i++){if(callback(array[i], i, array)){newAr..
Advanced Array Methods(map) map: Creates a new array Iterates through an array Runs a callback function for each value in the array Adds the result of that callback function to the new array Returns the new array function map(array, callback){var newArr = [];for(var i = 0; i < array.length; i++){newArr.push(callback(array[i], i, array));}return newArr;} /*Write a function called doubleValues which accepts an array and retu..
Advanced Array Methods(forEach) ForEach: Iterates through an array Runs a callback function on each value in the array returns 'undefined' function forEach(array, callback){for (var i = 0; i < array.length; i++) {callback(array[i], i, array);}} /*Write a function called doubleValues which accepts an array and returns a new array with all the values in the array passed to the function doubledExamples: doubleValues([1,2,3]) // [..
4 Ways AJAX(xhr / fetch / jquery / axios) var url = 'https://ron-swanson-quotes.herokuapp.com/v2/quotes';var quote = document.querySelector("#quote");var xhrbtn = document.querySelector("#xhr");var fetchbtn = document.querySelector("#fetch"); //XHRxhrbtn.addEventListener("click", function(){ var XHR = new XMLHttpRequest(); XHR.onreadystatechange = function (){ if(XHR.readyState == 4 && XHR.status == 200){ var data = JSON.parse(XHR.respo..
Fetch Random User Profile Generator 코드리뷰 Udemy The Advanced Web Developer Bootcamp에서는 프로젝트 중심으로 강의를 진행하고있다. 강의를 한번듣고 바로 좋은 코드를 작성하진 못하지만 이런 리뷰를 통해서 코드에 대한 이해도가 더 생겼으면 좋겠다.1var url = "https://randomuser.me/api";1var url = 'https://randomuser.me/api/';2var name = document.querySelector("#fullname");2var fullnameDisp = document.querySelector("#fullname");3var img = document.querySelector("#avatar");3var avatar = document.querySelector("#a..
AJAX XHR(XML HTTP Request) var btn = document.querySelector("button");var display = document.querySelector("#price");var currency = "USD"; btn.addEventListener("click", function(){var XHR = new XMLHttpRequest(); fetch(url) XHR.onreadystatechange = function(){ .then(function(response){ if(XHR.readyState == 4 && XHR.status == 200){ return response.json() var data = JSON.parse(XHR.responseText); }) var ..
Async Foundation Callback function: a function that is passed into another function as a parameter then invoked by that other function(usecases: Advanced Array Methods, Broswer events, AJAX Requests, React Development) A higher order function: a function that accept a callback as a parameter Use a callback function to make your code more general Create callbacks using anonymous functions Foreach function: functi..