Javascript Flashcards
<p>+</p>
<p>Returns the sum or 2 numbers or concatenates 2 strings</p>
<p>%</p>
<p>Modulo Returns the remainder of the first value divided by the second</p>
Javascript Primitive Data Types(5)
String, Number, Boolean, Null, Undefined
<p>2 + "2"</p>
<p>Concatenation = 22</p>
10 > 2
returns true
typeof()
tells us what the type is typeOf(10<2) returns boolean
Javascript Null
A value does not exist
Javascript Undefined
The variable has yet to be defined
Javascript prompt
Creates and alert box that accepts an input; var x = prompt(“what is x”);
Random number between 0 and 5
var _randNum = Math.round(Math.random() * 5);
Check if number is divisible by 3
if (x%3 === 0)
Property
Values of an object Dog.breed breed is property; noun
Method
A function that is associated with an object; verb
object literal
Define and create an instance at the same time var person = {Name: “Bill”, Age: 5}
object constructor
function Person (name, age) {this.name = name; this.age = age;}
Host objects
Objects defined by the environment; console is a common host object used in a browser
Core objects
Objects defined by Javascript examples: Math, String, Boolean, Array
global object
The window is the global object when the host environment is the web; window.alert() === alert()
Local Scope
Variables created inside a function can’t be accessed from outside the function. (Variables created within a function that do not use the var keyword are added to global scope)
Function scope
Every time we create a new function the scope changes
Closure dictionary definition
A combination of a function bundled together (enclosed) with references to its surrounding state (the lexical environment)
Closure laymans definition
A closure gives you access to an outer functions scope from an inner function. In JS closures are created every time a function is created at function creation time.
Why are closures used
To give objects data privacy; variables can be manipulated in a different scope
Closure benfites
Keep dataprivate;