Introduction to Javascript Flashcards

1
Q

Javascript runs…

A

on the browser rather than the server. Whereas before in order to perform action, data and operations were being sent to the server.

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

Javascript is an _____ programming language

A

interpreted

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

Javascript Alerts

A

alert(“Text to Display Alert”);

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

JS Data Types

A

Different Types
String
Boolean
Number

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

typeof()

A

Output of function
“number”
“boolean”
“string”

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

JS Variables

A

prompt(“Dialogue to display for prompt”);
To declare a variable use, var.
var, variables can later be changed to a different value
Example:
var myName = “Anand”;

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

Naming and Naming Conventions for JS Variables

A

Variable names cannot start with a number

Variable can only contain numbers, letters, $, and/or _

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

Variables follow a camel-case format.

A

First word contains lowercase, then subsequent words contain capital letters for their names

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

String Concatenation

A

Can combine strings using +
Example:
“Hello” + “World” -> “HelloWorld”

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

String Lengths and Retrieving the Number of Characters

A

To check the number of characters in a string

stringVariable.length

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

Slicing and Extracting Parts of a String

A
Slice Function
stringslice(x, y);
Slices the string from x to y. Including x, up to but not including y
Example:
“Anand”.slice(0,3);
“Ana”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Changing Casing in Text

A
toUpperCase()
Example:
“word”.toUpperCase()
“WORD”
toLowerCase()
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Basic Arithmetic and the Modulo Operator in Javascript

A
Modulo
%
Gives the remainder of a division
Example:
9 % 6 = 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Increment and Decrement Expressions

A

x++
x = x + 1;
x- -
x = x - 1;

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

Creating and Calling Functions

A
Declaring functions:
function myFunction() { <code> }
Calling a function
myFunction();</code>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Function Parameters and Arguments

A
Example:
function getMilk(money) { … }
17
Q

Function Outputs and Return Values

A

Include a return statement in the function to make it a function that has an output

18
Q

Control Statements: If-Else Conditionals and Logic

A

if ( condition ) { < code to run, if condition is true > }

else { < code to run, if condition is false> }

19
Q

Comparators and Equality

A
===
Is equal to
Checks both for the value and the data types
!==
Is not equal to
>, =
==
Only checks if the values equate to each other.
Doesn’t take into account the data types
So, 1 == “1”, will be equal to true
20
Q

Combining Comparators

A
&& 
AND
|| 
OR
!
NOT
21
Q

Javascript Arrays

A
Creating an array
Example:
Empty Array
var names = [];
Prefilling an array with elements
var names = [“Bob”, “John”, “Jennifer”];
Retrieving an element from an array
Example:
names[1]; // “John”
Array elements always start at 0
Retrieving the number of elements in an array
Array.length // Return the number of elements
Checking if an array contains a specific element
Array.includes(  );
Returns a boolean
22
Q

Adding Elements and Intermediate Array Techniques

A

Adding an element at the end of an array
Array.push( );
Remove and retrieve the last element of an array
Array.pop(); // Returns the last element of the array

23
Q

While Loops

A

while ( ) { // Code to run }

24
Q

For Loops

A

for(startingCondition ; conditionToRunLoopIfTrue; conditionModifier) { // Code to run if condition is true}
Example:
for(i = 0; i < 100; i++) { // Run code}