JavaScript Flashcards

1
Q

javascript vs java

A
  • js is interpreted, java is compiled
  • similar syntax
  • js is more relaxed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

data types

A

Primitive:
- number (99, 0.8, -1)
- string (“hello”)
- boolean (true or false)
Complex:
- undefined (var x;)
- Objects (special)
- function (user-defined)

objects are special data types that have functions and data associations

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

javascript arithmetic

A
  • a + b
  • a - b
  • a / b
  • a * b
  • a**b (exponential)
  • a % b (modulus)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

javascript arithmetic shortcuts

A
  • a++ and a– to add or subtract 1 from a number variable
  • a+= b is a = a+ b (and same for -,/,*,%)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

javascript arithmetic precedence

A

BEDMAS

brackets, exponents, division/multiplication, addition/subtraction

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

== and ===

A

equivalency and strict equivalency; check to see if the value is the same and check to see if the value AND data type are the same

ex. string “5” compared to number 5 is true for == and false for ===

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

Javascript comparison operators

A
  • == (equal to)
  • === (equal to and equal type)
  • != (not equal to)
  • !== (not equal to or not equal type )
  • > (greater than)
  • < (less than)
  • > = (greater than or equal to)
  • <= (less than or equal to)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

number to string conversion trick

A

numberVar = numberVar + “”

concatenation of a number and string type creates a string

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

control statements

A
  • if/else if/else
  • while/do-while loops
  • for loops
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

function syntax

A

functionName(param1,param2..etc) {
function code
}

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

deterministic vs nondeterministic loops

A

for vs while

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

var vs let vs const

A

var is function scope let and const is block scope

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

string concatenations

A

“hello” + “world” = “helloworld”
“hello” + “ “ + “world” = “hello world”
“hello” + 123 = “hello123”
123 + “” = “123”

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

Style Guide

A
  • camelCase for identifiers
  • avoid $
  • identifiers start with _ or letters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

JS Events

A

Things like clicks, entering text, etc.

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

event handler

A

function onClick () {
}

16
Q

html elements associated with events

A

<button>
<input></input></button>

<textarea>
</textarea>

16
Q

DOM

A

Every element (tag) in an HTML page is an object that can be accessed in JS through the document object via dot notation

17
Q

addEventListener and removeEventListener

A

takes two parameters, event name and function name

17
Q

dot notation

A

Each element’s properties and methods can be accessed using dot notation:

element.style.color = white;

17
Q

DOM examples

A

const element = document.querySelector(‘img’);
element.src = ‘newImg.png’;
element.style.background.color = ‘blue’;

18
Q

changing an element’s class

A

the classes used in css can be added or removed using:

.classList.add(‘className’);
.classList.remove(‘className’);

19
Q

event objects

A

implicitly passed to the handler methods of the function:

function onClick(event) {
const clickSrc = event.currentTarget
}

20
Q

other DOM properties

A

element.id
element.value
element.innerHTML (unsecure)
element.textContent

21
Q

DOM element creation/removal

A

let element = document.createElement(tag);
element.appendChild(anotherElement);
element.remove(anotherElement);

22
Q

recursion

A

-never more efficient as it’s iterative counterpart
-used when the problem itself is recursive by nature (merge/quick sort, tree traversal, balanced strings, etc)

23
Q

stack frame (activation record)

A

contains all info necessary for tracing a function call; parameters, local vars, return addresses, etc

when a function is called it’s stack frame is created, initialized, and pushed on to the stack

when a function is finished its stack frame is popped off the stack