Chapter 2: Basic Javascript Instructions Flashcards

1
Q

Statements

A

An individual instruction or step in javascript. Ends with a semi colon

var today = new Date();

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

Comments

A

Used to explain code. You can have multi line using syntax /* */ or single line using // syntax . Any script surrounded by a comment is not processed by the js interpreter

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

Is Javascript a case sensitive language?

A

Yes. hournow and hourNow would be treated as two different items

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

code block

A

lines of code surrounded by curly braces { } do not end in a semi colon

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

Variable

A

variables are used to store bits of information. If you need to reuse a piece of information you’re best to store it in a variable. Programmers say you declare a variable. You can then assign it a value. Variables stand in for a value, so rather than saying the specific number it represents (which may change), its use whatever is stored in this item instead

var dinosaur = “Spinosaurus”;

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

=

A

This is the assignment operator. it assigns a value to a variable.

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

undefined

A

Until a variable has a value its undefined

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

Data types

A

Javascript variables can have a range of types.
numeric (e.g. 2, 0.75)
String (“Used for text)
Boolean (results in a true or false value)

There’s also arrays, objects, undefined and null

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

Quote marks

A

Used to mark out strings. You can use single or double but they must match i.e. don’t start with string ‘ and end with “

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

escaping quotes

A

Used when you want to show quote marks inside a string.

You can either use a backslash before a quote mark or Start the string with double quotes and then use single quotes inside the string

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

Booleans are useful…

A
  1. When a value can only be true or false

2. When code can take more than a single path (allows us to test if a condition/s are true or false)

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

Rules for naming variables

A
  1. must begin with a letter, dollar sign or underscore
  2. names can contain letters, numbers, $ or an underscore
  3. You cannot use keywords/reserved words
  4. case sensitive
  5. use a name that describes the info that the variable stores
  6. camelcase
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Array

A

Arrays store a list of values or related values. The values are indexed by a number starting at 0.

Using an array is useful instead of creating individual variables when you are unsure of the number of items

var colours = [‘white’, ‘black’, ‘red’];

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

array literal syntax vs array constructor sytax

A
literal:
var colours = ['white', 'black', 'red'];
constructor:
var colours = new Array ('white', 'black', 'red');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Access values in an array

A

by index number

var colours = [‘white’, ‘black’, ‘red’];

colours[2];

by item

var colours = [‘white’, ‘black’, ‘red’];

colours.item(1);

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

What does array.length do?

A

Returns how many items are in the array

17
Q

What is an expression?

A

An expression evaluates to a single value.

we can either assign a value

or

write an expression that uses two or more values to return a single value

18
Q

What is an operator

A

It’s a tool that allows us to combine multiple values into a single value.

Assignment, Aritmatic, String (+ this combines strings and numbers together concatenates)

19
Q

What is the % modulus operator

A

When doing division it returns the remainder

20
Q

When would I get NAN?

A

If you used artistic operators with values or variables and the result would not return a number