Section 3: Types and Operators Flashcards
Dynamic Typing
You don´t tell the engine what type of data a variable holds, it figures it out while your code is running. Variables can hold different types of values because it`s all figured out during execution
What keyword exist to tell the engine what kind of data you intend to put inside a variable?
There is NO keyword
What is a primitive Type?
A type of data that represents a single value
An object is a primitive type?, and why?
not, because an object is a collection of name / value pairs
How many primitive types exist in JS
6 primitive types
Name the 6 primitive types in JS
undefined
null
boolean
number
string
symbol
Describe the primitive type: Undefined
Represents lack of existence, its what the JS engine sets variables to initially and it will stay undefined unless you set the variable to have a value.
Describe the primitive type: Null
and when its useful
represents lack of existence (you can set a variable to this).
its useful when you want to represent that something doesn´t exist, that the variable has no value(set a variable to nothing).
Describe the primitive type: Boolean
Either true or false, just one of two values
Describe the primitive type: Number
Exist other numeric types in JS?
There’s only one numeric type.
Its a floating poing number (there
s always some decimals)
Describe the primitive type: String
What we use to define a string?
A sequence of characters (both ‘’ and “” can be used)
Describe the primitive type: Symbol
It`s defined in ES6
What is an operator?
It`s a special function that is syntactically (written) differently. Generally operators take 2 parameters and return one result.
How did the JS engine that this was my intent to add 3 and 4?
var a = 3 + 4;
console.log(a); // result: 7
The syntax parser saw the plus(+) sign and added these 2 numbers.The plus sign is an operator, it’s actually a function.
What is the name of the notation that the JS engine provide to deal with operators.
Inflix notation
What it means “inflix notation”
Inflix mean that the function name, the operator, sits between the 2 parameters.
When we type these operators, +, -, >, <, what is happening?
How these operators works?
These operators are a special type of functions, that the parameters between the operators are being passed to those functions and a value is being returned
Inside those functions is prewritten code, for you that the JS language provides to do or run, or invoke these functions.
What is operators precedence?
It´s which operator function gets called first, functions are called in order of precedence (HIGHER precedence wins)
What is operator associativity?
What order operator functiosn get called in: left-to-right or right-to-left, and this means when the operator functions have the same precedence
What is the purpose of operator precedence and associativity?
help us determine which function run first and so does associativity.
When comes into play operator associativity?
Associativity comes into play when two or more operators have the same precedence
What is coercion?
It´s converting a value from one type to another.
Why coercion happens in JS?
Because it´s dynamically typed
How coercion and operators relate, and what we need to understand from this?
We understand that operators are functions, so they`re running code, and coercion is part of that process of calling that function, coercion happens because JS it´s dynamically typed.