Algorithm Challenges Book Flashcards
What is the purpose of coding a FUNCTION?
For code that you expect to use often, whether called by various places in your own code, or perhaps even caled by others’ code, you can separate this out and give it a specific label
What are the six (primitive) data types in javascript?
Number, String, Boolean, Undefined, Null, Symbol (new in ECMAScript 6)
What is unique about number in Javascript?
Makes no distinction between integers and floating-point numbers
Describe the difference between x = y and x == y
x = y, set the value of x to become the value of y
x ==y, is the value of x equivalent to the value of y?
Assign y to x
Are x and y equal?
How is javascript type? (loose? strict?)
It is loosely typed: it very willingly changes a variable’s data type, whenever needed.
The == operator ACTUALLY means ‘after converting x and y to the same data type, are their values equivalent?’
If you want strict comparison without converting data types, then you will use the === operator
What is the developer console?
The developer console is where errors, warnings and other messages about our program go.
The console.log function always takes what type of data type?
The console.log function will always take in a string. If we send it something that isn’t a string, JS will first convert it to a string that it can print.
Calling the function is also referred to as
Running or executing the function.
In Review: when we DECLARE a function, it allows some other caller to execute our function from some other place in the code, at some other time.
What are the complex conditional values? (and, or, not)
And is &&
Or is ||
Not is !
What is the difference between a for and while loop?
For loops are useful when you know how many times tnhose lines of code will run. While loops are slightly better when you don’t know how many times to loop, but you will loop WHILE a certain test continues to be true.
How do you create a for loop?
You specify three things within parentheses following the for: any initial setup, a test that must be true in order to start the loop, and any code to be run at tend of each time through the loop.
What are other ways of writing num = num + 1?
num = num +1, can be equally written as:
num +=1
num++
++num
Note: You could also decrement by num–; or –num; there are also *= and /=
Describe BREAK and CONTINUE
With more complex code, you might need to break out of the loop early, or to skip the current pass but continue looping.
Break immediately exits the specific loop you are currently in and continues immediately following the loop.
Continue skips the rest of the current pass through the loop, but any loop=end statement is executed and looping will continue.
With both, once they run, any subsequent code within the loop is skipped.
What is a parameter?
In ordert to increase functionality and flexibility of a function, you use parameters.
The function caller simply inserts these values (called arguments) between parentheses, when it executes the function.
What is a return value?
Parameters give functions a lot more flexibility. However, sometimes you don’t want a function to do all the work; maybe you just want it to give you information so that then your code can do something based on the answer it gives you. This is when you would use the return value for a function!rt