Beginner JavaScript Flashcards
JavaScript runs in your web browser alongside HTML and CSS, and can be added to any web page using a _______ tag.
script
What are the three types of JavaScript included in HTML pages?
- ) Internal
- ) External
- ) Inline – Should be avoided
What is the file extension used by JavaScript files?
js
Storing data so we can use it later is achieved with ______.
Variables
var surname = prompt(‘Greetings friend, may I enquire as to your surname?’);
Prompt the user to enter a surname and store the contents of that response in a variable named surname.
What are the two parts to a variable?
The variable’s name and value
What are the two steps to creating a variable?
declaration and initialization
What is the variable declaration?
Declaration is declaring a variable to exist.
What keyword is used to declare a variable?
var
What is Initialization?
Initialization is giving a variable its value for the first time.
What is a string?
A collection of letters. A string is surrounded by single or double quote marks.
What is assignment?
It looks very similar to initialization. You use the equals sign, but there’s no need for the var keyword because we’ve already declared the variable.
What capitalization convention does this variable name use: piecesOfFruit?
Camel casing
Mathematical symbols are called _______.
Operators.
+, -, *, /, %
When a comparison is made the outcome is either true or false; a special kind a of data called a _____. This is _____.
boolean and logic
What operator should be used to find out when two values are equal?
triple equals operator (“===”)
What operator should be used to find out when two values are NOT equal?
triple not equal operator (“!==”)
What operators are used to determine which value greater or less than another?
greater than operator (“>”)
less than operator (“
What operators can be used to determine greater than or equal to? Less than or equal to?
greater than or equal to (“>=”)
less than or equal to operators (“<=”)
______ is used to make decisions in code
Logic created with conditionals
What is the most commonly used conditional?
if or if-else
How does the if statement work?
if some logic (the condition) is true, run a block of code, else run a different block of code
The code between the braces - “{” and “}” - is called a _______.
A block
_______ are a way of repeating the same block of code over and over.
Loops
What the two most commonly used types of loops?
- ) for
2. ) while
How do loops work?
They combine a conditional and a block, running the block over and over until the logic of the conditional is no longer true, or until you force them to stop.
A ______ repeats a block of code while a condition is true
while loop
_______ combines three semicolon-separated pieces information between the parentheses: initialization, condition and a final expression.
for loop
________ are reusable blocks of code that carry out a specific task.
Functions
To execute the code in a function you _______.
call it or invoking the function
A function can be passed _______ to use
arguments
A function may _______ a value to whatever called it.
return
How to create a function?
- ) Use the function keyword
- ) List arguments in parenthesis
- ) Create a block of code that creates functionality
In a function, the _____ keyword also stops execution of the code in the function; nothing after it will be run.
return
var add = function (a, b) { return a + b; };
What are a and b?
Parameters
JavaScript objects consist of what two parts?
properties and methods
An object can be stored in a variable, and the properties and methods accessed using _________.
dot syntax
What are object properties?
pieces of data
What are JavaScript methods?
Functions that are built into objects
var jedi = { name: "Yoda", age: 899, talk: function () { alert("another... Sky... walk..."); } };
What are name and age?
Properties – Essentially variables that are built into objects
True or False? Properties can be any kind of data including objects and arrays
True
What is a nested object?
An object that is a property of another object
True or False? You can create an empty object and then add properties and methods to it.
True
________ are lists of any kind of data.
Arrays
Each item in the array has an ______ — a number — which can be used to retrieve an element from the array.
An index
Array indices start at _____
0
The last element of an array has an indices of ______
The length of the array minus 1
In JavaScript, you create an array using the _____ syntax:
array-literal syntax
Example: var shoppingList = [‘Milk’, ‘Bread’, ‘Beans’];
You retrieve a specific element from an array using _____ syntax
square bracket syntax
Example: shoppingList[0]; // retrieve a value
Example: shoppingList[1] = ‘Cookies’; // set a value
What is length?
shoppingList.length;
The array length property.
You can use _____ and ______ methods to add and remove elements from the end of the array
push and pop
Example: shoppingList.push(‘A new car’);