JavaScript Flashcards
1
Q
JavaScript Characteristics
A
- Executes code in the user’s browser, allowing our code to interact with the rendered HTML and CSS
- Creates less stress on the server and a better experience for the user
- 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
2
Q
Java vs JavaScript
A
- Java requires a runtime (JRE) and Virtual Machine (JVM) - JavaScript requires a runtime engine in the Browser (client-side)
- 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.
- 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)
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.
4
Q
Falsy values in JS
A
falsy (evaluate to false): false, 0, ‘’, null, undefined, NaN
5
Q
Truthy values in JS
A
truthy (evaluate to true): everything else
6
Q
Scope
A
- Global Scope.
- Block Scope.
- Function Scope.
- let and const - obey block and function scope.
- var - ignores block scope, and obeys function scope.
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.
8
Q
Block Scope
A
Works like block scope in Java.
9
Q
Function Scope
A
Variable can be used anywhere in a function that it is declared in.
10
Q
Arrays
A
- Defined by [].
- Not confined to a single data type.
- Not a fixed size.
11
Q
Methods (not a complete list)
A
- length()
- concat() ← joins to arrays into 1
- push() → adds an element to the end of an array,
- pop() → removes the last element from an array
- unshift() → adds an element to the start of the array
12
Q
Object Literals
A
- Defined with keys and literal values as being declared.
- Objects assigned to a variable.
- Defined as a comma-delimited block of key: value pairs.
- let x = {} ← declares an empty object.