cheatSheet2.0Final Searchable
cheatSheet2.0Final Searchable
function Hedstot vale?) { let mapa=new Map(); mise then( ope Coe elector
Clonetodelirel
console.log(x): mapa.set('mile’,'car’); func ’ " le. in: sec 'on.query ol
; mapa.get(mil) /undefined Tuncton(result) {console.log(result:}, (".item1").textContent = "aaa";
} I // ako resolve, result = "dobro izvrsen” seclion.querySelector
let f2 = function(x) {console.log(x);} mapa.has( mile’); function(error) {console.log(error);} "i " src=" ".
) mapa.delete("mile"); u ' ¢ ’ (".tem2").src = "x.png";
let f3 = (x) => console.log(x); m // ako reject, result = "lose izvrsen" document.body.appendChild(section);
arrays \\ apa.clear() ); let sections =
letarr =[1,2,3,5,6,1,7.8]; promise.catch( document.querySelectorAll(".container”);
let last = arr.pop(); // makne i returna zadnji function(error) {console.log(error);}// samo ako reject for (let section of sections)
arr.push(4); // append na kraj ) { section.remove(); } // brisanje svih
let first = arr.shift(); / makne i returna prvi promise.catch(
arr.unshift(5); // ubaci na pocetak function(error){console.log(error);}
arr.splice(1,2); // brise 2 elementa od indeksa 1 ).then(
let arr2 = [6, 7]; function(result){console.log("Resolve:"+result)},
let arr3 = arr.concat(arr); // spoji function(result){console.log("Reject:"+result)}
arrd = arr3.slice(1,3); /indexi od 0, 1 element,2 element, 3 ne ); // calch ce uhvalit error, u then se ce pozvat prva funkcija s result = undefined
console.log(arr4.includes(6)); //vraca value,ne bool //Fetch\y
arr.sort( function(a,b){return b - a} ); // sort sa komparatorom (desc) let promise2 = fetch("htips://web1lab2.azurewebsites.net/products?categoryld=1");
arr.reverse(); promise2.then( // obraduje se promise od fetcha
arrEven = arr filter( (x) => x%2==0); function(response) {
for (let element of arr) {console.log(element);} // element if (Iresponse.ok) { throw new Error("Cannot load"); }
for (let index in arr) {console.log(index);} // indeksi else { return response.json(); } // novo obecanje reponse.json()
// classes, objects \ 1,
class Person { function(error) { throw error; }
lastName = "Doe"; )-then( // obraduje se promise od response.json
age = 50; function(response) { console.log("Loaded JSON"); }
constructor(firstNameValue) {this.firstName = firstNameValue;} ).catch( // catch hvata gresku u bilo kojem promiseu
get lastName() {return this.lastName;} function(error) { console.log(error); }
set lastName(newLastName) {this.lastName = newLastName} )
1 /ILoadJsonty
let person = new Person("John"); async function LoadJSON() { // funkcija se izvodi asinkrono
personi.lastName = "Williams”; let promise = await fetch("htips://web/categoryld=1");
person.firstName = "Jake"; // unutar funkcije, await se izvodi sinkrono (ostatak funkcije ceka)
for (let value of Object.values(person1)) {console.log(value)} if (foromise.ok) { throw new Error ("Cannot load"); }
// try-catch \\ else { var jsonContents = await promise.json(); }
try { console.log(jsonContents);
throw "error"; }
} catch(err) { LoadJSON().catch(
console.log(err); (error) => {console.log(error);}
} finally{ )
var x =2; }
o body = common bone <body> /* Extra small devices (phones, 600px and down) */
lel head = document head: aa @media only screen and (max-width: 600px) {...}
let bodyChildrenElements - body.children; // samo html elementi bb I Small devices (ablets and large phones.800px and up) */
’ ’ <h1 class="c2"> Naslov </h1> @media only screen and (min-width: 600px) {...}
let bodyChildren = body.childNodes;
J sadri | tek “a bb" ie ied | Kit <p id="i1" class="c2"> Paragraf </p> /* Medium devices (landscape tablets, 768px and up) */
sadrzi i te st npr “aa Je Jedan clan, te svaki in </body> @media only screen and (min-width: 768px) {...}
let h1 = body.firstElementChild; . !
pt [a Ui. firstChild /* Large devices (laptops, 992px and up) */
| samo’ oot pe h oa. za sve let newP = document.createElement("p"); @media only screen and (min-width: 992px) {...}
he Th - v as oe Chit newP.innerHTML = "novi paragraf"; /* Extra large devices (large laptops, 1200px and up) */
samo film element, -fastChild za sve body.appendChild(newP); @media only screen and (min-width: 1200px) {...}
let answer = prompti("name?", default");
let p = h1.nextElementSibling; // local storage \\
let response = confirm("cookies?");
h1 = p.previousElementSibling; let Is = window.localStorage;
/1 JSON W Module2.js
body = h1.parentElement; Is.setltem("item”, 2);
let person = {firstName:"John" import sum from "./module1.js
p = document.getElementByld("i1"); let keyAtindex0 = Is.key(0);
hd Sel "om: Jf lekior , lastName:"Doe", age:50, eyeColor:"blue"}; let length = Is length: let result=sum(a,b)
= document.querySelector(".c2"); // css selektori let personJSON = JSON. stringify(person); et length = Is.length;
p_h1 = document.querySelectorAll(".c2"); let personFromJSON = JSON. parse(person SON): let item = Is.getltem( item”); Modulel.js
p.style.backgroundColor = "Red"; Is.removeltem("item"); export function sum(a, b){
p.innerHTML = "promjena teksta"; Is.clear(); return a+b }