https://medium.com/@prashantramnyc/javascript-closures-simplified-d0d23fa06ba4
Interview challenge : getMovieTitles
Myriad Systems.
To solve this challenge, write an HTTP GET method to retrieve information from a particular movie database.
https://stackoverflow.com/questions/48448432/fragment-of-missing-code-in-the-solution-movie-titles-complete-a-challenge-more
function getMovieTitlesData(title, page = 1) { const url = 'https://jsonmock.hackerrank.com/api/movies/search/?Title=' + title + '&page=' + page; console.log('URL:',url); const titles = []; return new Promise((resolve, reject) => { fetch(url, { method: 'get', }).then((response) => { return response.json(); }).then((jsondata) => { for (let i = 0; i < jsondata.data.length; i++) { titles.push(jsondata.data[i].Title); } var total_pages = Number(jsondata.total_pages); var curpage = Number(jsondata.page); resolve({ titles : titles, page : page, total_pages : total_pages }); }).catch((error) => { console.log("Failure", error); }) }) } function getMovieTitles(substr) { const promises = []; const titles = []; getMovieTitlesData(substr).then(result => { titles.push(...result.titles); for (let i = result.page + 1; i <=result.total_pages; i++) { promises.push(getMovieTitlesData(substr, i)); } Promise.all(promises).then(datas => { datas.forEach(data => { titles.push(...data.titles); }); console.log(titles.sort()); }); }) } getMovieTitles('spiderman');
Same origin policy in javascript
Under the policy, a web browser permits scripts contained in a first web page to access data in a second web page, but only if both web pages have the same origin. An origin is defined as a combination of URI scheme, host name, and port number. This policy prevents a malicious script on one page from obtaining access to sensitive data on another web page through that page’s Document Object Model.
let and const in Javascript
Difference between jquery and modern javascript
HTTP statuses
ES6 / ES2015 Additions
Arrow functions (or fat functions)?Arrow functions (or fat functions)
An arrow function expression is a syntactically compact alternative to a regular function expression, although without its own bindings to the this
, arguments
, super
, or new.target
keywords. Arrow function expressions are ill suited as methods, and they cannot be used as constructors.
The key difference, despite being shorter to write, is that arrow functions do not create their own value for ‘this’.
If the function body contains just a single statement, you can omit the brackets and write all on a single line:const myFunction = () => doSomething()
https://flaviocopes.com/javascript-arrow-functions/
(parameters) => { statements }
Arrow functions and Lexical this
https://hackernoon.com/javascript-es6-arrow-functions-and-lexical-this-f2a3e2a5e8c4
Template Strings / Template Literals
https://wesbos.com/javascript-template-strings/
Object Destructuring
https://dev.to/sarah_chima/object-destructuring-in-es6-3fm
Adding to Array
[…oldArray, itemToAdd]