Grammar and types Flashcards
What are the three kinds of variable declarations
var - Declares a variable, optionally initializing it to a value
let - Declares a block-scoped, local variable, optionally initializing it to a value
const - Declares a block-scoped, read-only named constant
What is a variable
Variables are symbolic names for values in your application
What are the rules for variable names
A variable must start with a letter, underscore (_) or dollar ($) sign
Subsequent characters can also be digits (0-9)
It is case sensitive so letters include both upper (A-Z) and lower (a-z) cases
What is variable scope
Variable scope can be either global or local
Global variable scope is when a variable is declared outside of any function and is available to any code within the current document
Local variable scope is when a variable is declared inside of a function and is only accessible within the function
What is variable hoisting
Hoisting refers to the lifting of variables to the top of the function or statement calling them
Variables that are declared after they are called are returned as “undefined” rather than throwing an exception
Describe function hoisting
A function declaration will run successfully without error as they are hoisted
A function expression on the other hand will return a TypeError indicating is not a function
List the primitive (or simple) data types
- Boolean - returns either true or false
- null - a variable with no value
- undefined - a variable that has been declared but no value assigned yet
- Number - an integer or floating point number
- String - a sequence of characters that represent a text value
List the complex data type
Object - this includes arrays and functions as both are considered types of objects