MST Flashcards
Question: What values can booleans in JavaScript have?
Answer: Either True or False, but not both at the same time.
Question: What purpose do functions serve in JavaScript?
Answer: Functions define a piece of code once that is needed in multiple places in the program, reducing total programming work.
Question: What are the usual guidelines for naming variables in JavaScript?
Answer: Names should be descriptive, and if using multiple words for a variable name, the first letter of the second and subsequent words should be capitalized; e.g., myVariable or rectEdgeColour.
Question: How do you indicate the end of a function in JavaScript?
Answer: You use a closing curly bracket ‘}’.
Question: What are for loops commonly used for in JavaScript?
Answer: For loops are often used to run a fixed number of times but can be finished early when required.
Question: Describe the use of variables let and var in functions in JavaScript.
Answer: let creates variables that only exist in the function; var creates variables that can be seen in the whole program. It is recommended to use let over var.
Question: What is the difference between ‘let’, ‘const’, and ‘var’ in JavaScript?
Answer: ‘let’ and ‘const’ are block-scoped variables, meaning they are limited to the block they are defined in. ‘var’ is function-scoped, allowing the variable to be accessed throughout the entire function.
Question: The special character ‘\’ is in fact just a single backslash, True or False
True
Explain the role of conditions in both for and while structures, stating what conditions do and how their outcomes affect the flow of the program
For loop is specific to lists (and other sequence types) While loop can be used with any data While loop is not just for lists Typically, for takes every item in a list, starting at the front While can skip items or move arbitrarily across the list
Explain the importance of the curly brackets in a while statement, and how to use brackets for an if statement when it is placed within the while block
Curly brackets in a ‘while’ statement are essential for defining the block of code that should be repeatedly executed as long as the condition is true. The curly brackets enclose the statements that belong to the ‘while’ loop. When using an ‘if’ statement within a ‘while’ block, the ‘if’ statement’s curly brackets define the block of code that should be executed conditionally within each iteration of the ‘while’ loop.
Explain the importance of the indentation in a while statement, and how to indent an if statement when it is placed within the while block
Indentation is used to indicate what is part of the while block, the code that will execute while the condition is True An internal if statement will need further indentation for its if and else blocks
When indentation ends, all code is executed after the while block finishes
Explain the role of integers and floating point numbers in JS, comparing and contrasting what values they can store.
for integer = whole numbers
for float = decimal fractions
for comparison, e.g. float can have slight errors; vs. integer is precise or comparing the other properties of the nums
Explain the difference in what happens when a number is divided by another, when using floating point as opposed to integer variables. Take the example of dividing seven by three
Floating point numbers will give 2.33333 in this case
Integer will give 2
Integers can get a remainder by another operation (%)
In this case, floating point is more precise
multiplying 2.3333 by 3 will give 6.9999 not 7
Explain why using a floating point number as an index into a list would be problematic, referring to how list index numbers work and the range of values that
are possible when using a floating-point number.
for saying the index is usually an integer
for conversion can be inaccurate
for e.g. 2.5 is valid float pt but hard to convert
for rounding error problems