JS1 - FoF
// This example shows how to ___ a variable and ___ it to an object using the ___ // 'Animal' is an ___ with ___ var Animal = { type: 'dog', sound: function() {console.log('woof!');} } // Use the sound() ___ Animal.sound();
declare; initialize; object literal syntax; object; properties; property
It's not best practice: you should really ___ a variable before you ___ it.
declare; use
Hoisting example: name = 'Astro'; function printName() {console.log('Current character is ' + name);} printName(); var name; Console.log returns ___.
'Current character is Astro'
A variable needs to be ___ before it can be used in JS code. There are three types of variable declaration: (3)
declared; var, let, const
Data Types: Eight data types are available for storing data using variables. These are: (8)
(1) Boolean (2) Number (3) String (4) BigInt (5) Symbol (6) null (7) undefined (9) Object
Two ways arrays are created: (1) ___ array syntax: ___ with values inside, separated by commas. var brands = ["Fender","VOX"]; (2) Array ___ var brands = new Array("Fender","VOX");
(1) Brackets; (2) Constructor
Eight data types are supported in JS for supporting data: (8)
1. Boolean 2. Number 3. String 4. BigInt 5. Symbol 6. Object 7. null 8. undefined
The ___ data type allows storing and operating on ___. A ___ can be created by appending ___ to the end of an ___ or by invoking a ___. Ex. let pageViews = 9999999999999999999999n // prints 9999999999999999999999n let pageViews = BigInt(9999999999999999999999); // prints 9999999999999999999999n
BigInt; large numbers; BigInt; n; integer; constructor
Arrays ___ contain values of ___ (including ___). And can have ___ arrays.
CAN; different types; objects; nested
Variables declared with let or var ___ be ___.
CAN; reassigned
Array Static Methods - Array.from(): ___ a ___ array from ___ array, ___, or ___. console.log(Array.from('123')); // returns ["1", "2", "3"]
Creates; new; another; iterable object; array-like object
Variable ___: A variable can be ___ in JS using the ___, ___, or ___ keyword. The ___ of a variable, called ___, must conform to certain ___.
Declaration; declared; var, let, const; name; identifier; naming rules
___ variables existing ___ of any ___, while ___ variables are ___ inside a particular ___.
Global; outside; function; local; inside; function
Variable ___: It __ possible to refer to a variable that is ___ using ___ ___ in code, which is called ___. But the ___ variable returns the value of ___.
Hoisting; IS; declared; var; later; hoisting; hoisted; undefined
Methods used to typecast - toString(): ___ used to convert a ___ to a ___.
Method; number; string
Methods used to typecast - parseFloat(): ___ used to ___ an ___ and return a ___.
Method; parse; argument; floating point number
Methods used to typecast - parseInt(): ___ used to ___ a ___ to an ___ or ___.
Method; parse; string argument; integer; NaN
If you have a global variable and then declare a local variable with the same name and change it inside the function, will it change the global one? They're considered ___ variables because the ___ is different.
NO; different; scope
___ and ___ both express an ___ of ___.
Null; undefined; absence; value
___ and ___ are two ___ in JS that ___ contain ___.
Null; undefined; primitive data types; CANNOT; values
// This example shows how to ___ a variable and ___ it to an object using the ___ // 'Animal' is a ___ that can be used to create an ___ function Animal() { this.type = 'dog'; this.sound = function() {console.log('woof!');} } // 'dog' is an ___ created from the 'Animal' ___ var dog = new Animal(); dog.sound()
Object() constructor; declare; initialize; constructor; object; object; constructor
JS Data Types: BigInt: A ___ data type that allows storing an ___ with an ___ format.
PRIMITIVE; integer; arbitrary precision
JS Data Types: Symbol: A ___ data type that can be used to define ___ and ___ values.
PRIMITIVE; unique; immutable
___ example: "use strict" topic = "Process Automation" // This will throw a ReferenceError error
Strict mode
___ enforces stricter rules when writing JS code. For example, a ___ cannot be used without being ___.
Strict mode; variable; declared
___ can be used to avoid ___.
Strict mode; hoisting
Wrapper Objects: ___, ___, and ___ data types cannot contain ___. However, each of these data types has an ___ that allows them to contain ___.
String, boolean, number; properties; Object wrapper class; properties
The ___ data type allows creating a ___. A ___ value can be created by invoking the ___. Ex: // ___ a Symbol variable let name = Symbol(); // A ___ can be passed to the function as its description let label = Symbol('label'); // Symbol variables are ___. The following creates two ___ symbols. let field1 = Symbol('field'); let field2 = Symbol('field'); // Both conditions below evaluate to ___ field1 === field2; Symbol('field') === Symbol('field);
Symbol; unique identifier; Symbol; Symbol function; Initialize; string; unique; false
What if we have a function that uses a (var) variable, but that (var) variable isn't declared till after the function is defined and invoked?
The function will still be able to access the variable--HOISTING.
___ is assigned by the ___. ___ is usually assigned by the ___.
Undefined; JavaScript engine; Null; developer
___ allows accessing a variable ___ it has been ___ in code, but a ___ variable returns the value of ___.
Variable hoisting; BEFORE; defined; hoisted; undefined
___ are used to store ___ in JavaScript.
Variables; data
Ex. let amount = 5123.4943 amount.toFixed(2) ^The above reduces ___ to ___.
amount; two positions
An ___ is an ___ of data. It can represent a collection of ___ or ___. It can be used to store ___ in a ___.
array; ordered collection of data; multiple values; single variable
An ___ is a special form of an ___ that provides a way to store an ___ of data. And can store ___ in a ___ with an ___.
array; object; ordered collection; multiple values; single variable; array
Variable Declaration - let: The let keyword can be used to declare a ___, ___ variable. The variable ___ be ___ to a ___.
block-scoped; LOCAL; CAN; initialized; value
Variable Declaration - const: The const keyword can be used to declare a ___, ___ ___. It ___ be ___ to a ___.
block-scoped; read-only; CONSTANT; MUST; initialized; value
In JS, a ___ is anything inside ___. Ex. An ___, a ___. Or we, can simply create a ___.
block; curly braces; if statement; function; block
How to access values inside an array: ___. brands[0]; ^ to access the ___ value
brackets; first
Array Static Methods: The Array ___ contains ___ that can be used in ___ or ___ an array.
class; static methods; constructing; determining
BUT with ___, you ___ to ___ a ___. And then you can no longer ___ it.
const; HAVE; assign; value; change
Considerations for initializing objects and arrays - Constant array: If an array is initialized using the ___ keyword, its ___ CAN still be ___.
const; elements; modified
When we assign a variable with ___, we CANNOT ___ the value.
const; reassign
Ex. object ___: var animal = new Object(); animal.type = 'dog'; animal.sound = function() {console.log('woof!');} Create the object ___.
constructor; first
When initializing ___ and ___, certain considerations should be kept in mind. For example, the ___ of an ___ or ___ that is declared using the ___ keyword ___ be modified.
objects; arrays; content; object; array; const; CAN
Considerations: Unlike ___, the ___ of an ___ or ___ that is initialized using the ___ keyword ___ be ___.
primitive data types; CONTENT; object; array; const; CAN; modified
Not all ___ can contain ___. Some data types are used to represent ___ or in the state of ___ being ___.
primitive data types; values; nothing; not; defined
JS Data Types: Number: A ___ data type that allows storing an ___ or ___.
primitive; integer; floating point number
JS Data Types: undefined: The undefined keyword represents a ___ value that is ___. It is ___ to a variable that as been ___ but not ___.
primitive; not defined; auto-assigned; declared; initialized
JS Data Types: String: A ___ data type that allows storing a ___ or ___ that represent a ___.
primitive; sequence; characters; text value
JS Data Types: Boolean: A ___ data type that allows storing the value of ___ or ___.
primitive; true; false
CAN contain values: These data types are used for ___ such as true, false, decimals, floats, integers, ___, ___, text, and unique values that are often used for object property keys.
storing values; NaN; Infinity
Can use ___ to prevent using ___ variables.
strict mode; undeclared
Ex. let str = '50'; Number(str) This is called ___.
typecasting
The ___ keyword returns the ___ of a ___. The ___ keyword returns ___ if a ___ is an ___ of an ___.
typeof; type; value; instanceof; true; value; instance; object
What values do variables have if they're not assigned a value?
undefined
Ex. console.log(typeof amount); // ___ console.log(amount2 instanceof Number); // ___
"number"; true
When a variable is ___ ___ of any ___, it is called a ___. If it is ___ ___ a ___, it is called a ___. The ___ of a ___ is based on where it is ___.
declared; outside; function; global variable; declared; inside; function; local variable; scope; variable; declared
When naming variables, it is a good idea to make them ___, so that you and others looking at your code can understand the purpose or the data it contains.
descriptive
JS ___ require you to specify the ___ when a ___ is ___. It is a ___ language.
does NOT; data type; variable; declared; dynamically-typed
Variables in JS are ___: You can ___ a variable, assign a specific ___ to it, and then later assign a different ___. Ex. ___ and then ___.
dynamic; declare; type; type; Number; String
This ___ nature also allows us to ___ one ___ to another.
dynamic; explicitly convert; data type
Considerations for initializing objects and arrays - Empty array elements: It is possible to create an array with an ___ by using ___. The ___ has the value of ___.
empty element; two commas in a row; empty element; undefined
Global variables are accessible from inside ___.
functions
Global and Local Variables: A ___ variable is a variable that is declared ___ of any ___. A ___ variable is declared ___ a particular___.
global; outside; function; local; inside; function
Again, variables can be ___, meaning they can be accessed ___ the code. Or they can be ___, meaning they are accessible only ___ the ___.
global; throughout; local; inside; function
This is called ____. The variable is available even ___ it is ___.
hoisting; BEFORE; declared
Naming rules for ___ of variables: ___ are ___.
identifiers; Identifiers; case-sensitive
Naming rules for ___ of variables: ___ and ___ can be used as characters in ___.
identifiers; Unicode characters; unicode escape sequences
Naming rules for ___ of variables: Each ___ must begin with a ___, ___, or ___. Characters that follow can be ___ or ___.
identifiers; identifier; letter, underscore, dollar sign; letters, digits
Considerations for initializing objects and arrays - Constant object: If an object is ___ using the ___ keyword, the ___ of the object ___ still be ___.
initialized; const; properties; CAN; modified
JS Data Types: Object: Can be used to store ___ and ___. It is ___.
keyed collections of data items; complex entities; NON-PRIMITIVE
A variable declared with ___ or ___ is ___. ___ is NOT.
let, const; block-scoped; var
If you declare the variable with ___ instead, though, you get a ___.
let; reference error
Since ___ and ___ are ___, they are only available ___ the ___.
let; const; block-scoped; within; block
Ex. object ___: var animal { type: 'dog', sound: function() {console.log('woof!');} } Use ___ to define object. Invoke like animal.sound();
literal; curly braces
Variable Declaration - var: The var keyword can be used to declare a ___ or ___ variable. The variable ___ be ___ to a ___.
local; global; CAN; initialized; value
Methods used to typecast - Boolean(): When used with the ___ keyword, a ___ is created. When used as a ___, a ___ is returned.
new; boolean object; method; boolean primitive
Methods used to typecast - Number(): When used with the ___ keyword, a ___ is created. When used as a ___, a ___ is returned.
new; number object; method; number primitive
Methods used to typecast - String(): When used with the ___ keyword, a ___ is created. When used as a ___, a ___ is returned.
new; string object; method; string primitive
Considerations for initializing objects and arrays - Existing variables and functions: When using the ___, a ___ of an ___ can be assigned to an ___ or ___.
object literal syntax; property; object; existing variable; function invocation
Example that shows using the object wrapper class of the number data type: // A numeric "amount" variable is initialized let amount = 5123.4943; // The variable is ___ to an ___ of the type ___ just before toFixed() is called amount.toFixed(2); // Alternatively, the wrapper object can be instantiated as below, but it is not necessary let amount2 = new Number(5123.4943);
object wrapper class; converted; Object; Number
An ___ can be created using the ___ or ___.
object; object constructor; object literal syntax
An ___ allows the storing of data in ___.
object; key-value pairs
JS Data Types: null: Represents any ___. It is a ___ and ___ value.
null value; CASE-SENSITIVE; primitive
A variable is ___ if it has been ___ a ___.
null; explicitly assigned; null
CANNOT contain values: The ___ data type is used to indicate that a value represents ___. An ___ variable has a value of ___.
null; unassigned; undefined
Considerations for initializing objects and arrays - Property names: A ___ or ___ can be used as a ___. It can also be an ___ or an ___.
numeric; string literal; property name; empty string; invalid identifier within quotes
Two ways to check if a variable is ___: - if(___ role == 'undefined') - if(role == ___) The latter works because ___ will be ___ to ___ and they'll be ___ to each other, if using ___ equal signs.
undefined; - typeof; - null; null; COERCED; undefined; equal; TWO
A variable is ___ if it has been ___ but no ___ has been ___.
undefined; declared; value; assigned
Since variables can have an ___ value, it's a good idea to ___ a variable before using it.
undefined; check
___ is not ___. You have ___ to it ___ of the ___.
var; block-scoped; access; outside; block
When a variable is declared using the ___ or ___ keyword and not assigned to an initial ___, its value is ___. It is a good practice to check if a variable has a ___ before executing code that utilizes it.
var; let; value; undefined
A ___ of one ___ can be ___ to another ___, which is called ___.
variable; data type; explicitly converted; data type; typecasting
It is possible to use a ___ that is ___ only ___ in the code using ___ due to ___. A ___ returns the value of ___. However, ___ and ___ variables are ___ but not ___ and therefor return a ___ if used.
variable; declared; later; var; hoisting; hoisted var variable; undefined; let; const; hoisted; initialized; ReferenceError
A ___ can be ___ using the ___, ___, or ___ keyword.
variable; declared; var, let, const
The name of a ___ is called an ___, and it must conform to certain ___.
variable; identifier; naming rules
A ___ points to a ___.
variable; storage location
Three of these primitive data types have ___ objects which provide access to ___ and ___: (3)
wrapper; properties; methods; 1. Number; 2. String; 3. Boolean
Considerations for initializing objects and arrays - Array literal: An array literal can consist of ___, each of which represents an ___.
zero or more expressions; array element