Chapter 2 - Basic Javascript Instructions Flashcards

1
Q

What is a script?

A

A script is a series of instructions that a computer can follow one-by-one

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

Each individual instruction in a script is also known as?

A

A statement - an individual instruction that a computer should follow. Each one should start on a new line and end with a semi-colon. This makes your code easier to read & follow

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

Each of the statements or instructions in a script should be followed by a

A

semicolon

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

what do the pink curly braces in scripts represent?

A

they represent the start and end of a code block. statements can be organized into code blocks. the closing curly braces isn’t followed by a semi-colon

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

each code block could contain more than 1 statement - true or false?

A

true

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

Is javascript case-sensitive

A

yes

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

What are some of the reasons why you should comment in your code.

What are the methods that can be used to comment in a javascript code

A

to explain what your code does. they help your code easier to read & understand. this can help you & others who read your code

multi-line and single-line

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

How to write multi-line comments

A

to write a comment that stretches over more than one line… /…./. Anything between these characters is not processed by the Javascript character… they are often used for descriptions of how the script works, or to prevent a section of the script from running when testing it

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

how to write a single-line comment

A

anything that follows the two forward slash characters //….. often used for short descriptions of what the code is doing

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

What is a variable?

A

A script will have to temporarily store the bits of info it needs to do its job. It can store this data in variables.

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

What is the #1 thing to do when using a variable?

A

declare the variable: announce that you want to use it - create the variable and give it a name

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

how to declare a variable

A

var name;

var = variable keyword
name = variable name (in order to use a variable, you must give it a name or an identifier. if a variable name is more than one word, it is usually written in camelcase - first word is all lower case and any subsequent words have their first letter capitalized)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how to assign values to variables?

A

once you’ve created a variable, you can tell it what info you would like it to store for you - you assign a value to the variable i.e. var quantity = 3; … you can now use the variable by its name. the equal sign is an assignment operator, it says you’re going to assign a value to the variable… until you’ve assigned a value to a variable, programmers say the value is undefined.

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

What are the javascript Data Types?

A
  1. Numeric Data Type: you’ll use numbers 0-9, no commas. Numbers aren’t only used for things like calculators, they’re also used for tasks such as determining the size of the screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.
  2. String Data Type: Consists of letters and characters. Enclosed between a pair of quotes (can be single or double but must match) - they’re frequently used to add new content into a page and they can contain html markup.
  3. Boolean Data Type: Can have one or two values: true or false. Booleans are helpful when determining which part of a script should run. Booleans are used when the value can only be true/false. You could also think of these values as on/off or 0/1: true is equivalent to on or 1, false is equivalent to off or 0. Also, Booleans are used when your code can take more than one path. Remember, different code may run in different circumstances
  4. Arrays
  5. Objects
  6. Undefined
  7. Null
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are some shorthand techniques for creating variables?

A
  1. Variables are declared and values assigned in the same statement.
  2. 3 variables are declared on the same line, then values assigned to each of them
  3. 2 variables are declared and assigned values on the same line. Then one is declared and assigned a value on the next line.
  4. Here, a variable is used to hold a reference to an element in the html page. This allows you to work differently with the element stored in that variable
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are rules for naming variables?

A
  1. The name must begin w/ a letter, dollar sign, or an underscore (_). It must not start with a number
  2. you must not use a dash (-) or a period (.) in a variable name
  3. no keywords or reserve words. keywords are special words that tell the interpreter to do something. Reserved words are ones that may be used in a future version of JavaScript (refer to text)
  4. all variables are case sensitive, so score & Score would be different variable names, but it’s bad practice to create two variables that have the same name using different cases
  5. Use a name that describes the kind of info that the variable stores i.e. firstName for someones first name
  6. If your variance name is made up of more than one word, use a capital letter for the first letter of every word after the first word i.e. firstName
17
Q

What are arrays?

A

A special type of variable. It doesn’t just store one value; it stores a list of values. Consider using an array whenever you’re working w/ a list or a set of values that are related to each other; also, when you don’t know how many items a list will contain b/c when you create the array, you don’t need to specify how many values it’ll hold. If you don’t know how many items a list contain, rather than creating a long list of variables, use an array. Values in an array don’t have to be the same data

18
Q

What ways can you create an array?

A

array literal - the preferred method… by writing each value on a separate line

array constructor - uses the “new” keyword followed by Array() - the values are then specified in the parenthesis and each separated by a comma.

19
Q

What is an Expression?

A

Evaluates into (results in) a single value. Broadly speaking there are two types of expressions. Expressions rely on 2 things called operators; they allow programmers to create a single value from one or more values

20
Q

What are the types of expression?

A
  1. Expressions that assign a value to a variable:
  2. Expressions that use two or more values to return a single value: you can perform operations on any number of individual values to determine a single value.
21
Q

List some of the arithmetic operators?

A

Addition + (Adds one value to another)
Subtraction - (Subtracts one value from another)
Division / (Divides 2 values)
Multiplication * (multiplies 2 values using an asterisk)
Increment ++ (adds one to the current number)
Decrement – (subtracts one from the current number)
Modulus % (divides 2 values and returns the remainder)

22
Q

What is the String Operator?

A

There is just one string operator: the + symbol. It is used to join the strings on either side of it - for situations where you may need to join two or more strings together to create one new string (concatenation)