JavaScript Flashcards

1
Q

JavaScript Characteristics

A
  1. Executes code in the user’s browser, allowing our code to interact with the rendered HTML and CSS
  2. Creates less stress on the server and a better experience for the user
  3. Uses:
    - Responding to an Event (mouse click, keypress, resize, etc.)
    - Interact with APIs to dynamically update a page
    - Manipulate the loaded page without needing to refresh
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Java vs JavaScript

A
  1. Java requires a runtime (JRE) and Virtual Machine (JVM) - JavaScript requires a runtime engine in the Browser (client-side)
  2. Java compiles to Bytecode - JavaScript is interpreted at Runtime. Interpreted means that it is never compiled to machine code. Instead, it is organized and then run by another program.
  3. Java is Statically Typed (Language enforces the data types once declared) - JavaScript is Dynamically Typed (Language infers the data type from the value it currently holds)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Variables

A
1. Declared with let if the value needs to change
let x = 10;
2. Declared with const if the value does need to change
const x = 10;
Preference should be const.   
3. Do not use var - outdated syntax that ignores the scope. Still used for some specific reasons (when we ignore scope). Unless you have a reason, don’t use it.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Falsy values in JS

A

falsy (evaluate to false): false, 0, ‘’, null, undefined, NaN

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

Truthy values in JS

A

truthy (evaluate to true): everything else

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

Scope

A
  1. Global Scope.
  2. Block Scope.
  3. Function Scope.
  4. let and const - obey block and function scope.
  5. var - ignores block scope, and obeys function scope.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Global Scope

A

Variables defined outside of a function are available everywhere, even in other js files that are included in the HTML.

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

Block Scope

A

Works like block scope in Java.

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

Function Scope

A

Variable can be used anywhere in a function that it is declared in.

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

Arrays

A
  1. Defined by [].
  2. Not confined to a single data type.
  3. Not a fixed size.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Methods (not a complete list)

A
  1. length()
  2. concat() ← joins to arrays into 1
  3. push() → adds an element to the end of an array,
  4. pop() → removes the last element from an array
  5. unshift() → adds an element to the start of the array
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Object Literals

A
  1. Defined with keys and literal values as being declared.
  2. Objects assigned to a variable.
  3. Defined as a comma-delimited block of key: value pairs.
  4. let x = {} ← declares an empty object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly