Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 2 out of 12 pages
Summary

Samenvatting Javascript cheatsheet Web Development II

Document preview thumbnail
Preview 2 out of 12 pages

Javascript cheatsheet Web Development II

Content preview

Hoofdstuk 1: Javascript basics
Script koppelen In HTML: <script src=”…”></script>
 Src = pad naar js bestand
Alert (pop up) alert(‘iets’);
Cijfer afronden tot x cijfers na de iets.toFixed(x);
komma
Grootste en kleinste getal Number.MIN_VALUE || Number.MAX_VALUE
+ en – oneindig Number.POSITIVE_INFINITY ||…
Afronden Math.round(getal);
Max/Min vinden array / lijst van Math.max(getal1, getal2, getal3);
getallen Math.min(getal1, getal2, getal3);
Datum maken Huidige tijd: const date = new Date();
Gekozen tijd: const date = new Date(jaar, maand, dag,
uur, minuut, sec, millisecond);
 Maand is 0-based!!
Uren etc uit datum halen Datum.getHours();
Enhanced for For(let key in myAvatar){…}
Of forof ipv forif
Functie definiëren function functie(par1, par2){…}
Array declareren Let pizzas = [];
Let pizzas = new Array();
Array: verwijder laatste element Pizzas.pop();
Array: voeg waarde toe opt eind Pizzas.push(“iets”);
Array: verwijder eerste waarde en Pizzas.shift();
return ze
Array: voeg waarde toe int begin Pizzas.unshift(“iets”);
Array: verwijder element op positie Delete pizzas[2];
 Returned undefined  Dan zit er een ‘empty’ in
Array: verwijder elementen op positie Pizzas.splice(startIndex, aantalEl);
Array: waarde invoegen Pizzas.splice(4,0, waarde);  waarde invoegen op index4
Array: arrays samenvoegen const array3 = array1.concat(array2);
Array: omkeren Pizzas.reverse();
Array: een stuk uit kopiëren Const array1 =array2.slice(2, 4);
 Array wordt dus niet aangepast  array1 zijn dus waarden met index 2 en 3
Array: sorteren Pizzas.sort(x);
 x is comparator bv x1.year – x2.year
Array: element zoeken Pizzas.indexOf(“margherita”);
 eventueel startend vanaf index
 geeft index weer Pizzas.lastIndexOf(“margherita”);
 -1 indien niet gevonden  Gaat van achter naar voor
Array: als string weergeven Pizzas.join(“-“);
 Met eventueel scheidingsteken
Array: destructuring: 1 kopiëren Const [pizza1, pizza2] = pizzas;  eerste 2 elementen
 Snel elementen uithalen ig Const [, , pizza3] = pizzas  3e element
 Nut: array kopiëren gaat niet adhv
a=b
Array: destructuring: kopiëren Const kopie = […pizzas]; kopie van Pizzas
Const link = pizzas;  hard link!

, Hoofdstuk 2: Objecten en functies
Object declareren Const mijnObject = {};
 Eventueel met attributen Const mijnObject = {
naam: “bob”,
letter: {el1: “A”, el2: “B”}
};
Attributen ophalen Const naam = mijnObject.naam;
 Kan ook functie zijn die je oproept Const letterEl1 = mijnObject.letter.el1;
Attributen toevoegen & invullen mijnObject.leeftijd = 20;
Attributen verwijderen Delete mijnObject.leeftijd;
Object destructuring Const { naam, letter : hoofdletter } = mijnObject;
 Zie ook HT2-ex1-objects vanonder  Variabelen maken met overeenkomende attribuut
v/h object (naam en hoofdletter)
 De waarde v/h attribuut letter wordt in de const
hoofdletter gestopt
Object overlopen For(let key in mijnObject){
 Voor elk attribuut in object Console.log(key: mijnObject[key]);
};
 naam: bob …
Alle keys in een array steken Let arr = Object.keys(mijnObject);
Functie toevoegen als attribuut mijnObject.functie = function (par1){…};
Functie met onbeperkt/ onbepaald Function functie(par1, par2, …etc){…};
aantal parameters  de parameter “etc” kan je dan bijvoorbeeld overlopen
me ne forof, foreach, …
 in combinatie met array  function functie(par1, par2, …[a,b,c,d]){…};
destructuring o zo kunde makkelijk aan de 4 eerste waarden
Arrowfunctie Function functie(par1, par2){…};
 bv in const functie steken  const functie = (par1, par2) => {…};
 uitvoeren moet met () achter!
Event op een element uit de html Const element = document.getElementById(‘id’);
 hover  element.onmouseover = () => {…};
 kan ook met eventhandler zie  element.onclick = () => {…};
verder  onload, …
Exceptie gooien & vangen try {
throw {
name: 'SomethingWentWrongError',
message: 'Something went wrong. You should fix it'
};
} catch (e) {
console.log(`Error ${e.name}: ${e.message}`);
} finally {…}

Of

Throw Error(‘rip’);

Document information

Study
Uploaded on
October 21, 2022
Number of pages
12
Written in
2022/2023
Type
Summary
$4.20

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
easyIT
4.0
(5)
Sold
85
Followers
30
Items
23
Last sold
3 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions