javascript Flashcards
What is a variable?
A keyword that’s used to store data.
Why are variables useful?
They can be ‘referenced’/re-used Any time and be used over and over again, thus saving time. If you don’t store data in a value (the return), then the computer does the calculations but that’s it. You won’t be able to retrieve that final result when you need it.
What two special characters can a variable begin with?
‘$’ and ‘_’ dollar and underscore. No dashes or periods in a variable name.
How do you declare a variable?
The ‘var’ keyword, then an identifier/variable name. One word written in camelCase.
How do you assign a value to a variable?
Var myVar = value. Equal sign then the value you want to assign.
Are variables case sensitive?
Yes
Which words cannot be used as variable names?
Other JS keywords or reserved words. ‘var’, ‘function’, ‘let’, etc. Numbers and symbols (besides $).
What is a string?
A primitive data type. A grouping of characters.
What is the string concatenation operator?
+ sign
What is the difference when it comes to using single quotes or double quotes (‘ ‘or” “)?
There is no difference in javascript, however if you want to use quotes inside of a string, you will have to escape them, or use the opposite (single or double quote) type of quote to surround the string.
How do youescapequotation characters?
Back slash before the character that needs escaping.
What is type coercion?
When two different data types are combined and both end up being one data type.
12+’hello’ turns into a string of ‘12hello’
What is a number in JavaScript?
Primitive data type that is any numeric value.
What is an arithmetic operator?
Something to perform mathematic equations.
Name four of the arithmetic operators?
+ - / % * ++ –
What is the order of execution?
Follows basic math, where multiplication and division happen before addition/subtration. Right hand side of equal sign, then left hand side. Use parenthesis to change order of operations. PEMDAS
What is a function?
Code that executes a code block. Collection of code that runs as one.
Why are functions useful?
They are -re-usable blocks of code. Saves time writing the same thing over and over. A way to store steps to be used later, for when functions don’t immediately run on page load.
How do you call a function?
Write out the function name with parenthesis and any arguments if you need them.
What are the parts of a function definition?
‘function keyword’, ‘function name’, parenthesis with parameters inside, and curly braces for the code block.
What is the difference between a parameter and an argument?
The are the same, however, it is a parameter when you are defining a function, and is an argument when when you are calling it.
Why is it important to understand truthy and falsy values?
So we can properly do comparisons without unintended results.
Why is the typeof an objectnull?
It’s a bug that is just accepted now because changing it would be the end of the internet.
What is the difference between null and undefined?
Null is purposefully set by the developer and denotes meaningful space. Undefined is generally an accident and is just straight up nothingness. Does not take up space in the memory.