Javascript

0.0(0)
studied byStudied by 1 person
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/56

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

57 Terms

1
New cards

Data types

  1. Primitive: string, bigint, undefined, null, symbol, boolean, number

  2. Non-primitive: object

2
New cards

undefined vs null

  • Undefined: declared but not intialized, no function return

  • Null: deliberate absence of val, removes ref

3
New cards

hoisting

default JS behaviour where all var and func declarations are moved on top of the scope

<p>default JS behaviour where all var and func declarations are moved on top of the scope</p>
4
New cards

debugger

adding this word to the code will trigger the browser’s debugger

5
New cards

‘==’ vs ‘===’

  • loose equality (==): makes type coercion

  • strict equality (===): compares values and types

var x = 2, y = "2";
(x == y) //true
(x === y) //false

6
New cards

type coercion

automatic conversion from one data type to another

7
New cards

string coercion

  • number + string: turns number to string

  • number - string: turns string into number

var x = 3;
var y = "3";
x + y // Returns "33"
x - y // Returns 0

8
New cards

falsy/truthy values

truthy vals will be coerced to true, falsy to false

  • falsy: false, 0, 0n, -0, ““, null, undefined, NaN

  • truthy: the rest

9
New cards

boolean coercion

  • if statements: will run if truthy

  • logical operators: returns one of the operands

    • OR: if first truthy, returns first. otherwise, returns second

    • AND: if both truthy, returns second. if one falsy, returns it

var x = 220;
var y = "Hello";
var z = undefined;
        
x | | y // Returns 220
x | | z // Returns 220
x && y // Returns "Hello"
y && z // Returns undefined

if( x && y ){ 
  console.log("Code runs" ); // This block runs
}   
        
if( x || z ){
  console.log("Code runs");  // This block runs
}

10
New cards

var vs let

  • let was added later

  • var has function scope, let has block scope

11
New cards

JS scopes

knowt flashcard image
12
New cards

JS is ___ typed

Dynamically/loosely

  • var type is checked at runtime

  • var can hold any data type

<p>Dynamically/loosely</p><ul><li><p>var type is checked at runtime</p></li><li><p>var can hold any data type</p></li></ul><p></p>
13
New cards

NaN property

Not-A-Number

  • val that isnt a legal number

isNaN("Hello") // true
isNaN(345) // false
isNaN('1') // false, since '1' is converted to Number type which results in 0 ( a number) 
isNaN(true) // false, since true converted to Number type results in 1 ( a number)
isNaN(false) // false
isNaN(undefined) // true

14
New cards

passed by value

passing a primitive var to another var will only pass the value

  • a new reference is created and receives value

var y = #8454; // y pointing to address of the value 234

var z = y; 
     
var z = #5411; // z pointing to a completely new address of the value 234
     
// Changing the value of y
y = 23;
console.log(z);  // Returns 234, since z points to a new address in the memory so changes in y will not effect z

<p>passing a primitive var to another var will only pass the value</p><ul><li><p>a new reference is created and receives value</p></li></ul><pre><code class="language-JavaScript">var y = #8454; // y pointing to address of the value 234

var z = y; 
     
var z = #5411; // z pointing to a completely new address of the value 234
     
// Changing the value of y
y = 23;
console.log(z);  // Returns 234, since z points to a new address in the memory so changes in y will not effect z</code></pre><p></p>
15
New cards

passed by reference

passing a non-primitive var to another var passes the reference

var obj = #8711;  // obj pointing to address of { name: "Vivek", surname: "Bisht" }
var obj2 = obj;
    
var obj2 = #8711; // obj2 pointing to the same address 

// changing the value of obj1
        
obj.name = "Akki";
console.log(obj2);
        
// Returns {name:"Akki", surname:"Bisht"} since both the variables are pointing to the same address.

<p>passing a non-primitive var to another var passes the reference</p><pre><code class="language-JavaScript">var obj = #8711;  // obj pointing to address of { name: "Vivek", surname: "Bisht" }
var obj2 = obj;
    
var obj2 = #8711; // obj2 pointing to the same address 

// changing the value of obj1
        
obj.name = "Akki";
console.log(obj2);
        
// Returns {name:"Akki", surname:"Bisht"} since both the variables are pointing to the same address.</code></pre><p></p>
16
New cards

IIFE

Inmediately Invoked Function

  • a function that runs as soon as it is defined

(function(){ 
  // Do something;
})();

17
New cards

JS strict mode

18
New cards
19
New cards
20
New cards
21
New cards
22
New cards
23
New cards
24
New cards
25
New cards
26
New cards
27
New cards
28
New cards
29
New cards
30
New cards
31
New cards
32
New cards
33
New cards
34
New cards
35
New cards
36
New cards
37
New cards
38
New cards
39
New cards
40
New cards
41
New cards
42
New cards
43
New cards
44
New cards
45
New cards
46
New cards
47
New cards
48
New cards
49
New cards
50
New cards
51
New cards
52
New cards
53
New cards
54
New cards
55
New cards
56
New cards
57
New cards