JavaScript Fundamentals

Andrew Watters
Flashcards by Andrew Watters, updated 3 months ago
169
2
0

Description

Set of JavaScript cards outlining basics such as primitive vs composite data types, simple arithmetic and logical operators, basic use of functions, objects (to incl. arrays) conditional statements and loops. Introduces the concepts of scope and context.

Resource summary

Question Answer
Object Literal Syntax Object Creation Syntax Copy (binary/octet-stream)
Primitive (Primary) Data Types The Primitive (or Primary) data-types in JavaScript are String, Number, Boolean, Undefined, Null and Symbol (new in ES6). Primitive types are considered value types. They are not objects, and have no methods or properties.
Composite (Reference) Data Types If a type is not one of the primitive data-types, it is almost always on object. These are considered reference types. Functions, Objects (including Arrays), Dates, and Regular Expressions are examples of composite data-types.
What is an Object? An object is a wrapper which may hold any number of key-value pairs. Values may be any of the Primitive data types (number, string, etc) or other Objects, Methods or Arrays.
Object Creation Object Creation (binary/octet-stream)
Setting/Accessing Object Properties Setting Accessing Properties (binary/octet-stream)
What is an Array? An array is a specific, list-like object in JavaScript. Instead of having key-value pairs, each value is accessed via its index (zero-based). Items in the Array are typically referred to as elements.
Array Creation Array Creation (binary/octet-stream)
Accessing Elements (Arrays) Accessing Elements Arrays (binary/octet-stream)
For Loop (Array) For Loop Array (binary/octet-stream)
For Loop (Object) For Loop Object (binary/octet-stream)
While/Do While Loops While Do While Loops (binary/octet-stream)
What is a function? Functions are stored snippets of code that execute when they are invoked. They can be declared anonymously or stored in a variable. A function can be defined with parameters, and receive arguments when it is invoked. Upon completion, the "return" keyword is used to pass data out of the function back to the global scope.
Function Declaration Syntax Function Declaration Syntax (binary/octet-stream)
Function Expression Syntax Function Expression Syntax (binary/octet-stream)
What is hoisting? What types of functions are hoisted in JavaScript? When a JavaScript file is loaded, function declarations are "hoisted" to the top of the code by the browser prior to the execution of any code. This allows them to be "known" and utilized/called before they are declared in the actual source-code. Function declarations are hoisted but function expressions are not.
Which of these functions will be hoisted, and why? Function Hoisting (binary/octet-stream) The multiply function will be hoisted because it is a function declaration. Since the subtract function is a function expression, it will not be hoisted.
+=, -=, *=, /=, %= (Arithmetic Assignment Operators) The arithmetic assignment operators perform the action of the +, -, *, / OR % operator and then re-assign the variable or property on the left to the resultant value. They are called the addition/subtraction/multiplication/division/remainder assignment operators (respectively).
+, -, *, /, % (Arithmetic Operators) The arithmetic operators perform the expected operations: addition, subtraction, multiplication, division and remainder, (respectively). note: The + operator is also used for string concatenation (adding strings together).
++, -- (Arithmetic Operators) The increment/decrement operators (respectively) increase/decrease the value of a number by 1. If called on a non-number they yield NaN.
% (Arithmetic Operator) Modulus Operator: Returns the remainder left over when one operand is divided by a second. Modulus Operator (binary/octet-stream)
= (Logical Operator) Assignment Operator: points (assigns) the value of the variable or property on the left to the value of the right operand. Assignment Operator (binary/octet-stream)
== (Logical Operator) Equality Operator: Compares value of two variables/properties, converting them to the same type for comparison. Equality Operator (binary/octet-stream)
=== (Logical Operator) Strict Equality Operator: Compares left and right operands, returning true if they are equal in type and value. If comparing two objects, will not check for "deep-equality" Strict Equality Operator (binary/octet-stream)
!== (Logical Operator) Strict Inequality Operator: Compares the value and type of the left and right operands, returning true if they are not equal and/or not of the same type. Strict Inequality Operator (binary/octet-stream)
!= (Logical Operator) Inequality Operator: Compares the left and right operands, returning true if they are not equal in value. If types differ, type is converted for the comparison. Inequality Operator (binary/octet-stream)
< , > (Logical Operators) Less than and greater than (respectively), compare whether one number is less/greater than another, returning true if so and false otherwise.
<= , >= (Logical Operators) The less-then/Greater-than (respectively) or equal to operators, compare whether one number is less/greater than, or equal to another, returning true if so and false otherwise.
! (Logical Operator) "NOT" Operator: Returns false is it's operand is "truthy" (evaluates to true in a boolean context) Not Operator (binary/octet-stream)
&& (Logical Operator) "AND" Operator: Returns true if both the left and right operands are "truthy" (evaluate to true in a boolean context) Logical And (binary/octet-stream)
|| (Logical Operator) "OR" Operator: Returns true if either the left or right operands are "truthy" (true in a boolean context). Checks the left operand first and exits with true if it is "truthy". Logical Or (binary/octet-stream)
? (Logical Operator) Ternary Operator: Checks if an expression is true, returning the value to the left of the : operator if so and the value to the right otherwise. Ternary Operator (binary/octet-stream)
Conditional Statement Syntax Conditional Statement Syntax (binary/octet-stream)
Ternary Operator Syntax Ternary Operator Syntax (binary/octet-stream)
What is a switch statement? The switch statement evaluates an expression, matching the expression's value to a case clause, and executes a block associated with that case. If no case is met, the "default" case will execute. Note: Switch statements can be used in lieu of a conditional or ternary statements
Switch Statement Syntax Switch Statement Syntax (binary/octet-stream)
What is a "truthy" value? "Truthy" values are values that evaluate to "true" in a boolean context. All values except NaN, null, undefined, 0 (typeof number), false and "" (empty string) are "truthy" in JavaScript.
What is a dialog? Dialogs are contextual message that stop JavaScript execution. They are commonly used to inform or provide feedback to the end user. Alert, confirm and prompt are examples and can all be accessed via the global "window" object.
What is context? Context references the object where the currently executing code exists. It refers to the value of the "this" keyword which, at the global level is the window object and determines which variables are accessible. Although often confused with scope, context is object-based whereas scope is function based.
What is scope? Scope refers to the current level at which variables are accessible within JavaScript. Every function will have its own scope and can access variables in its own scope and at the global scope (accessible anywhere). Although often confused with context, scope is function based whereas context is object based.
What is the difference between Scope and Context? Fundamentally, scope is function-based whereas context is object-based. All functions have both a scope and a context (because they are objects) but objects only have context, and no scope.
Scope Syntax (Example) Scope (binary/octet-stream)
Context Syntax (Example) Context (binary/octet-stream)
Show full summary Hide full summary

Suggestions

Food Technology - Functions of ingredients
evie.daines
Respiratory System
Addeana
Art & Design in Context
Chloe Scott
Algebra Quiz
Norman McBrien
Functions of a Political Party
Phoebe Fletcher
A Streetcar Named Desire- Context Quiz
Grace Fawcitt
B1 Conditionals recap
Esther Alabart
The Merchant of Venice by William Shakespeare - context
Ona Ojo
Flash cards on cardiovascular system
offintowonderland
Conditional Sentences Quiz .
Ricky Rutledge
Quiz - Object Oriented Javascript
arunram.krish