MST Flashcards

1
Q

Question: What values can booleans in JavaScript have?

A

Answer: Either True or False, but not both at the same time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Question: What purpose do functions serve in JavaScript?

A

Answer: Functions define a piece of code once that is needed in multiple places in the program, reducing total programming work.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Question: What are the usual guidelines for naming variables in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Question: How do you indicate the end of a function in JavaScript?

A

Answer: You use a closing curly bracket ‘}’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Question: What are for loops commonly used for in JavaScript?

A

Answer: For loops are often used to run a fixed number of times but can be finished early when required.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Question: Describe the use of variables let and var in functions in JavaScript.

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Question: What is the difference between ‘let’, ‘const’, and ‘var’ in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Question: The special character ‘\’ is in fact just a single backslash, True or False

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Explain the role of integers and floating point numbers in JS, comparing and contrasting what values they can store.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Finally, explain how to convert Strings into both integers and floating point numbers, taking the example of a string containing “103”:

A

int() is used to create an integer number from a string
e.g. int_value = int(“103”)
or float_value = float(“103”
float() is used to create a fp. No. from a string

17
Q

Explain what a function is in JS, and the role of parameters in sending values to a function.

A

Function is some code that can be called from anywhere in a program
A function has a name to identify it Parameters are used to send data to the function from elsewhere
They are indicated in brackets after the name

18
Q

Some functions can use special return values to indicate that they could not perform their usual task. Sometimes this means returning a magic number, and sometimes using the value None.

Explain briefly why special values are returned, giving a simple example case where it might be used

A

Special values are used when an unusual result occurs
For example, when an item isn’t found when a list is searched Example result, or detailed explanation of when it happens Equally, defn. of magic no. or None

19
Q

What is cookies does?

A

Cookies are data stored in a small text files on our computers

20
Q

What does cookies do?

A

When a web server sends a webpage to a browser, the connection shuts down, and the server forgets everything about the user. Cookies help us to remember information about the user. When a browser requests a webpage from a server, cookies belonging to the page are added to the request.

21
Q

What does cookies do?

A

When a web server sends a webpage to a browser, the connection shuts down, and the server forgets everything about the user. Cookies help us to remember information about the user. When a browser requests a webpage from a server, cookies belonging to the page are added to the request.

22
Q

What are cookies used for?

A
  1. Session management
    -Cookies let the websites recognize users and recall their individual login information and preferences such as sports news vs. politics
  2. Personalization
    -If you view certain items on a website, cookies use this data to help build targeted ads
  3. Tracking
    -Shopping sites use cookies to track items users previously viewed, allowing the sites to suggest other goods they might like and keep the items in a shopping cart while the users are shopping
23
Q

How to save cookies?

A

document.cookies=”username=John Doe”

expiry date:
document.cookies=”username=John Doe”; expiresThu, 01 Jan 1970 00:00:00 UTC”;

24
Q

The client (web browser) is better for

A
  • Validating User input before it is sent
    -Animating graphics on the webpage
    (or anything else needing a fast response time )
25
Q

The server is better for

A

-Retaining data between individual webpages
-Storing actions that need to be taken remotely(payments, order)

26
Q

What is CGI?

A

CGI(Common Gateway Interface)

Foundation for a lot of server-side technologies