Webbprog Flashcards

1
Q

Vilka datatyper har JS?

A

undefined, boolean, number, bigint, string, symbol
- structual type - object
- structual root - null

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Vad är typeof

A

en opertaion som returnerar en string som visar vilken type en operand eller function är av

  • typeof null === “object”
  • typeof function() {) === “function”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Vad menas med att JS är dynamically typed?

A
  • variabler kan byra typ under programmets gång utan att behöva deklarera typen, datatypen bestäms vid exekvering, inte vid deklaration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Assignment i JS?

A

associerar namnet med new <value, type>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

när sker type conversion i js ?

A

endast när värdet användes inte när det tilldelas
tex: typeof Number(’42’) // ’number’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

vad är type coercion ?

A

js konverterar autoamtiskt values när det behövs
tex- 3 + ’42’; // ’342’
3 == ’3’ // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

String are mutable or immutable ?

A

immutable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Js with literals and qoutation marks

A

’single quotation mark’
* “double quotation mark”
* ‘string templates
can span multiple lines
and contain embedded expressions: 1+2=${1+2}‘

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s falsy

A

false, 0, null, “”,’’,``

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

vad gör chaining operation xxx. ?

A

access property eller kallar på en funktion, undefined om object är null eller undefined, inget error kastande

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

vilka 4 lika med operationer finns det ?

A
  1. abstract equality ==, !=
  2. Streict equality ===, !==
  3. Object.is()
  4. Same value - hanterar NaN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Vad händer när man deklarerar en funktion

A

statemnet som skapar ett funktions objekt och en variabel med funktions namnet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

exempel på en funktion som dubblar values från en array

A

const array1 = [1, 4, 9, 16];
const map1 = array1.map(function(x) { return x * 2 });

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

vad är default parameters?

A

parametrar som default har undefined om inget annat anges

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

vad är rest parameters?

A

samlar all rest arguments in i en array och måste nman ges i funktion signaturen

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

vad är arguments objektet i js?

A

array liknande objekt som innehåller alla argument passat från en funktion, sakanr array likande metoder

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

hur får man åtkomst till andra argumentet i en funktion med arugments objektet?

A

function foo(a, b, c) {
console.log(arguments[1]);
}
foo(1, 2, 3);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

vad är en arrow funktion ?

A

compakt syntax för anonyma funktioer, har inte this, arguments eller super

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

skriv en arrow funktion som räknar ut en kvadraten av ett nummer

A

let sqr = x => x*x;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

vad är functions orienterad programmering i js?

A

js tillåter funktioner att skickas som argument, kan användas i methoder som filter, map och reduce

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

hur hade man chainat filter, map och reduce för en array ?

A

[1, 2, 3, 4, 5]
.filter(x => x % 2 === 0)
.map(x => x + 2)
.reduce((sum, x) => sum + x, 0);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

vad är closure?

A

en funktion som kan använda variables från outer scope, även när yttre funktionen har slutat köras

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

vilka olika scopes finns det ?

A

function scope - var
block scope - let och const

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

exempel på closure

A

function foo() {
let cnt = 0;
return () => cnt++;
}
let idGenerator = foo();
console.log(idGenerator());

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

vad är function scope ?

A

variables deklarerade med var får scope inom funktionen eller globalt

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

vad är block scope?

A

variabler deklarerade med let eller const har bara scope i blocket de är deklarerade i som i ajva

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

vad är hoisting?

A

varaibler och funktioners deklaration flyttas till toppen av deras scope innan exekvering men initaliseringen sker på samma plats

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

ge ett hoisting exempel

A

function foo() {
console.log(x);
var x = 3;
console.log(x);
}
foo();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

vad är objekt definierade?

A

objekt har key to value parning, man kan accessa properties med .
obj.prop eller obj[‘prop’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

hur skapar man ett object literal ?

A

{prop: value}
const myObj = {name: ‘Per, age: 12}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

hur skapar man ett objekt med en kosntruktor?

A

function Person(name, age) {
this.name = name;
this.age = age;
}
const per = new Person(‘Per’, 30);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

hur tar man bort property fårn ett objekt ?

A

delte myObj.propertyName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

hur exporterar och importerar man moduler i js ?

A

// Export (my-module.js)
export function cube(x) {
return x * x * x;
}
// Import (some-code.js)
import { cube } from ‘./my-module.js’;

33
Q

vad hände rom man anger extra eller färre parametrar

A

koden förs ändå ingen error

34
Q

vad är this ?

A

värdet på this beror på hur funktionen blir kallad,

35
Q

hur gör man så att this referar till korrekt objekt i en metod

A

använd closure eller en arrow funktion för att behålla värdet på this

36
Q

hur fungerar prototype based inheritance?

A

alla objekt ärver från ett annat obejt eller null, skapar en prototype chian

37
Q

vad är properties ?

A

values kopplat till ett objekt
let obj = { name: “Emily”, age: 23 };
console.log(obj.name); // Accessing property

38
Q

vad är protoype?

A

objekt ärver features från en annan. varje objekt har prototype,. objekt kan dela metoder genom deras prootype

function Person(name) {
this.name = name;
}

Person.prototype.greet = function() {
console.log(“Hello, “ + this.name);
};

let emily = new Person(“Emily”);
emily.greet(); // Inherited method from prototype

39
Q

vad gör Object.create() ?

A

skapar ett nytt objekt med specifierad protoype

40
Q

vad är … ?

A

spread operator
expands array or objekt
let arr = [1, 2, 3];
let newArr = […arr, 4, 5]; // [1, 2, 3, 4, 5]

41
Q

vad är en statisk web page?

A

sida som inte kan byta content dynamiskt, visas såsom den är från servern

42
Q

vad är en dynamisk web page?

A

kan ändra content dynamiskt, använder server och client side sscripting

43
Q

vad är basic structure of HTML ?

A

<!DOCTYPE html>

<html>
<head>
<meta></meta>
<title>Page Title</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>

44
Q

namnge semantic HTML tags

A

<h1>, <p>, <nav>, <header>, <footer>, <article>, <section>.
</section></article></footer></header></nav></p></h1>

45
Q

namnge non semantic tags

A

<div>, <span>
</span></div>

46
Q

common attributes i HTMlL ?

A

id, class, href, src, alt, title, style

47
Q

HTMl form elements ?

A

A: <form>, <input></input>, <label>, <button>, <select>, <textarea>.</textarea></select></button></label>

48
Q

vad är CSS?

A

cascading style sheet
- för layout och styling

49
Q

vad är CSS layout properties

A

display, psotion, z-index, overflow, visibility

50
Q

CSS display property

A

block, inline, none, flex grid

51
Q

CSS positioning

A

static, relative, absolute, fixed, sticky

52
Q

vad är DOM ?

A

tree strcutre av en web page’s element, vi manipulerar trädet med JS

53
Q

hur får vi åtkomst till ett DOM element?

A

document.getElementByID(),
document.querySelector()
document.getElemntByTagName()

54
Q

vilak 3 faser av event propagation finns det i DOM

A

capturing phase, target phase, bubbling phase

55
Q

hur sker event handling i js

A

addEventListener() eller inline handerls onclick=”myfunction()”

56
Q

hur löser react de begränsningarna med HTMl och CSS ?

A

REact gör så attt js kan generera HTML träd och uppdatera DOM nät states ändras och skapa reusable komponenter

57
Q

vad gör en react render function ?

A

returnerar ett DOM liknande träd mha JSX och React inject detta trädet i DOm

58
Q

vad är JSX ?

A

JSX är syntax soms er ut som HTML men används i React för att besrika UI structure och compiles dwont o React.creteElement() calls

59
Q

how do you embed js expressions in JSX

A

js in JSX with {} curly braces

60
Q

how do you handle conditions in JSX ?

A

<div>
{isLoggedIn ? <h1>Welcome back!</h1> : <h1>Please sign in.</h1>}
</div>

61
Q

vad är en react komponent ?

A

en js function son retunrerar JSX

62
Q

how do you pass dara from parent comp to child comp ?

A

data is passed thorugh props, parent comp sets as attribute in JSX

63
Q

how do you handle events in react?

A

event handlers in camelcase like onClik = {handleClick}

64
Q

What is the role of state in React comp

A

using useSTate hook to declare state and a function to update it

65
Q

what is the key rule for react render functins?

A

render function should only return jsx not chanign state ro cause the UI to behave unexpectedly

66
Q

how does components share state in React

A

lift it to a common parent comp and passing it down as props to child component. allows mult comp to acces and sync the same state

67
Q

what is controleld component in react ?

A

form input element where value is controlled by react state. when user types react update the state changes the state and update the input value

68
Q

what is an uncontrolled component?

A

forms input managed by browser DOm and useRef is used to access values directly

69
Q

why are keys important when rendering lists in REact ?

A

keys help react identify which items have changed, added and removed

70
Q

what are react hooks ?

A

function slike useState and useEffect that let you hook into react state and life features form function components

71
Q

what use useEffect for this.

A

can perform side effects like data fetching and updating the DOM after rendering

72
Q

what is context in react ?

A

context allows you to broadcast data tp al componennts in a subtree wothput passing props through every level

73
Q

what is reducer ?

A

reducer is a function that tells us how the state hsuold change in reponse to actions , use dwith useReducer för state logic

74
Q

what does ReactDOM.render() do

A

renders react comp into a DOm element and updates the DOM

75
Q

what is the 3 stages of a react comp life?

A

mount, update, unmount

76
Q

diff URI vs URL

A

URI - id for resource
URL - id for location of resource, URL subset of URI

77
Q

how does browser history work in web routing ?

A

browser history allow susers to navigate back to prev visited pages . in SPA the DOM is updated without losing the application state

78
Q

what is the purpose of a react router?

A

manages navigation, routing, updating the URL and rendering comp based on the route without reloading the page

79
Q

what does <link></link> comp in router ?

A

<link></link>

comp allowa users to navigate between routers, updating browser history and URL without fetching a new page