JavaScript (Duckett) chap 2 Flashcards

1
Q

What can be included in statements?

A

Lol anything and everything:

Data (they definetely need these foundations)
Array (helps organize data numerically)
Variables (help store data and makes use easy)
Code block (contain variables & expressions)
Expressions (way of making var work together)
Methods (var & methods used to accom. tasks)

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

What is a codeblock

A

A codeblock is represented by parentheses { }.
These hold statements, usually for methods (like the if method). When you think code block just thing a series of statements that work best inside a method, so a method can be called and the code block can be easily utilized.

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

How would you create a variable?
How to put values in it?
How to use it?

A

You declare a variable into being when you create it so in Js you write: var A;

Kinda like screaming VARIABLE A! But instead of the exclamation you have a semicolon because that’s how you end a statement.

To put a value inside a variable you assign a value to the variable by using the assignment operator (=). Very very simple: A = 2;

To use the variable you need to understand scope but mainly simply include the var. name.

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

Variables are ways of storing data, what are the data types available to store in variables?

A

6 data types:
Booleans (true, false)
strings (text in quotes)
numbers (integers, real num, floating ., sci not)
null ( zero value where they used to be or not)
undefined data (never assigned a value)
Object (complex data like arrays & methods)

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

What is an assignment operator

A

He equals sign (=). You’ll see the assignment operator whenever you want to assign a value to a variable of some kind. You’ll use it a lot. Operators are things that help programmers write mathematical expressions easily and quickly.

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

An operator is used to help programmers write expressions quickly and easily. What are examples of operators?

A

+ - x / = are all mathematical operators used with data, the last one being used to assign values. The plus used to con😺enate or join two data types together.

Js code specific operators are:

– Decrement
++ Increment
% Modulus (divides 2 values, retrns remainder)

+= , -=, *=, /=, %= (quick ways to write exprss)
E.g., x += y is same as saying x=x+y
E.g., ‘leave’ += ‘now.’ is ‘Leave now.’
E.g., t1= ‘stay’, txt1 += ‘now’; t1= ‘stay now’
These are assignment operators (like = )

String operators are + (and only +).

Comparison & logical operators
== (equal to)
=== (equal value & equal type)
!= (not equal)
!== (not equal value or equal type)
>, = ,
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what is scope in relation to variables

A

functions in programming are a world unto their own, they exist in their own sphere. Whereas everything outside a function is considered global. So if you declare something in a function it is a function-level variable which is also called a local variable. Always declare your variable in your function with the var keyword. If it is not DECLARED it is in the global scope.

If a variable is declared outside the local-level (lol) then it’s a global variable in the global scope. Global variables can be used inside functions, and can even have the same name as a local variable but in this case they should not be used inside a global scope.

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

Talking about strings how would you escape a quote in a string data type in javascript?

A

You’d escape it using forward slash just before the quotecyiu want to escape.

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

When naming your variables what’s the general rule to use.

A

Use camelCase, which means to use lower case letters only except for when starting a new word then you use a upper case letter as the next words first letter.

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

What is a shorthand way to quickly declare a bunch of variables?

Ways to declare and assign values to variables?

A

To quickly declare variables you could declare a bunch of variables at once: var a,b,c;

To declare a variable & assign a value to it:
var a = 5; 

This is better than declaring a variable in one line, then assigning a value to it in another line.

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

An array is a way to store data in your variable (arrays are objects and are also a data type, as are objects). What characters are used to type in an array into your text file.

A

Arrays use square brackets [ ]. In Js you’ll use the brackets when you create, access or use arrays. Very easy.

So you’s say var a = [‘one’,’two’,3];

Arrays are great because they bring a numeric order to your data items. Arrays call their items indexes, starting with index item one. To access or use an array you’d enter a[0]

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

What are expressions?

A

Expressions evaluate into a value. Math can’t be done without expressions, coding can’t be done easily without expressions. They simply utilize operators to give a new value. An example of a popular mathematical expression is 1 + 2. The value of this expression being its solution.

A = 1+2, the A is a variable (not the expression)

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

5 kinds of operators are

A
Arithmetic operators
String operators
Assignment operators
Comparison operators
Logical operators
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A script of text is

A

A set of instructions for the browser to follow. Typically line by line and each line is a statement, like a sentence, every statement ends with a semicolon (;).

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