Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
106 Cards in this Set
- Front
- Back
how is javascript limited in the way that other programming languages are not?
|
-javascript only works inside another application - the web browser
-can't access local files -can't directly access database -can't access hardware, USB, etc |
|
what is javascript mainly used for
|
to add interactivity to web pages
|
|
when was javascript developed and by who with what company?
|
1995 by brendan eich at netscape
|
|
what is an interpreted language vs a compiled language and which type is javascript?
|
complied languages need to be run through compiler where your code is converted into machine code so then it can run on the OS. with an interpreted code, the code is written and then interpreted by the, in the case of javascript, the browser.
|
|
is Javascript case sensitive
|
yes
|
|
statements
|
the grouping of javascript code, they are separate instructions or commands to say piece by piece what you want your script to do
|
|
what punctuation mark is used to end a javascript statement
|
semicolon
|
|
is javascript whitespace sensitive?
|
no
|
|
syntax for commenting out single line
|
// comment
|
|
syntax for commenting on multiple lines
|
/* this is for multiple
lines of code */ |
|
does the position of your javascript in your code matter and why
|
yes, because the browser will render the code in the order in which its read, so for example, if you put an alert in the head, the browser will read the alert, and until you click ok, it will not render the rest of the page
|
|
where is, for the most part, the best place to add your script tag and why
|
just before the closing body tag of the html because the browser parses the code and if it's in the beginning, it's going to read the javascript before it reads the rest of the html which could slow down the load time
|
|
variable
|
a container for programming that holds a piece of computer memory and giving it a name so we can use it while our javascript is running
|
|
example of syntax for javascript variable and what does the year represent
|
var year; year represents the name of the variable
|
|
what can you use for variable names
|
letters, numbers, the underscore sign and the dollar sign
|
|
can you start a variable name with a number
|
no
|
|
how do you set a value for a variable?
|
add an equals sign and then give it a value
|
|
example sytnax of variable with a value
|
var year=2013;
|
|
are variable names case sensitive
|
yes
|
|
if creating more than one variable at the same time, what is an example in syntax of another option other than giving each one it's one line
|
var year=2011, month=10, day=31;
|
|
example syntax of undefined variable
|
var myVariable;
|
|
example of syntax of defined variable
|
var myVariable=200;
|
|
conditional code syntax example
|
if (condition) {// code goes here
//.. } |
|
what are paranthesis used for in conditional coding
|
to mark out whatever the condition is
|
|
what are braces used for in conditional coding
|
to mark out what we'll do if the condition is true
|
|
what must the condition always evaluate as
|
true or false
|
|
what are several statements surrounded by braces called?
|
code block
|
|
example of checking equality in a condition
|
if (a ==200) {
// code goes here //.. } |
|
when checking equality in javascript, what must you always use?
|
either double or tripple equal signs
|
|
example of full syntax using condition
|
var amount=500;
if ( amount < 1000) { alert("It's less than 1,000"); } |
|
what is this statement saying in layman's terms:
var amount=500; if ( amount < 1000) { alert("It's less than 1,000"); } |
you're declaring a variable of amount and setting it equal to 500
if the amount of is less than 500, then we'll execute whatever is between the braces |
|
syntax for conditional code if you want something else to happen if the if statement is false
|
if ( ) {
//code goes here //.. } else { //otherwise, different code } |
|
three ways to include javascript in html file
|
1) code a separate external javascript file and code a script element in the head section of the HTML document to include that file
2) include javascript within the script element in the head section 3)include javascript in an html document |
|
example syntax for external javascript file with script element in the head section
|
<script src="calculate_mpg.js"></script>
|
|
name given to variables, functions, objects, properties, methods and events so that you can refer to them in your Javascript code
|
identifier
|
|
rules for creating identifiers
|
-can only contain letters, numbers, the underscore, and the dollar sign
-can't start with a number -are case-sensitive -can be any length -can't be the same as reserved words -avoid using global properties and methods as identifiers. |
|
what does it mean that you should give identifiers a meaningful name
|
for instance, for a monthly investment, you should write it out as monthly_investment instead of abbreviating as mon_inv
|
|
camel casing
|
when identifiers have two words and the first letter of each word is capitalized except the first word, for example taxRate
|
|
other option other than camel casing for identifiers
|
using underscore between words, for example tax_rate
|
|
what is an object
|
has methods that perform functions that are related to the object as well as properties the represent the date of attributes that are associated with the object
|
|
what does a method do
|
performs a function or does an action
|
|
what is a property
|
a data item that relates to the object
|
|
what does call mean in javaScript
|
to execute
|
|
syntax for calling a method of an object and break down in layman's terms
|
ojbectName.methodName (parameters)
first code the object name, then add a dot operator (period), then the method name, then any parameters that the method requires |
|
three common methods of the window object
|
alert(string)
prompt(string,default) print() |
|
alert(string)
|
method that displays a dialog box that contains the string that's passed to it by the parameter along with an OK button
|
|
prompt(string,default)
|
method that displays a dialogue box that contains the string the first parameter, the default value in the second parameter, and OK button, and a Cancel button. When the user enters a value and clicks OK, the value is returned as a string. Or if the user clicks Cancel, null is returned
|
|
print()
|
method that issues a print request to the browser
|
|
example syntax for alert method
|
window.alert("This is a test of the alert method");
|
|
what is important to remember about the window object
|
it is the global object of javaScript, which means it can be omitted when a method is written. for example , var userEntry = prompt("This is a test of the prompt method", 100);
|
|
how to access a property of an object and example syntax
|
code the property name after the dot operator. for example, alert(window.location);
|
|
three primitive data types in javaScript
|
1)number data type
2)string data type 3)Boolean data type |
|
number data type and example
|
use to represent numerical data, for example 15, -21, 21.5, etc
|
|
string data type
|
use to store character data, for example "JavaScript", 'String Data'
|
|
Boolean data type
|
used to store true and fals values, for example true, false
|
|
empty string
|
quoted with two of the same quotation types one after the other, "", used to represent a string with no data in it
|
|
numeric expression
|
can be as simple as a single value or it can be a series of operations that result in a single value
|
|
modulus operator and syntax
|
calculates the remainder when the left value is divided by the right value, for example with the modulus operator 13 % 4, the result is 1
|
|
increment operator and example
|
adds 1 to the variable, for example, counter++
|
|
decrement operator and example
|
subtracts 1 from the variable, for example, counter--
|
|
variable
|
stores a value that can change as the program executes
|
|
how to declare a numeric variable in JavaScript
|
code the var (for variable) keyword followed by the identifier (or name) that you want to use for that variable
|
|
assignment statement and example
|
assigns a value to a variable. consists of a variable name, and assignment operator like =,and an expression. for example, var subtotal = 74.95;
|
|
most useful assignment operators and what they do
|
=, assigns the result of the expression of the variable
+=, adds the result of the expression to the variable |
|
how to declare variables and assign value to them
|
var subtotal=74.95; //subtotal=74.95
var salesTax=subtotal * .1; //salesTax=7.4 |
|
compound assignment operator
|
+= modifies the variable on the left of the operator by adding the value of the expression on the right to the value of the variable on the left. example:
var subtotal = 74.95; // subtotal = 74.95 subtotal += 20.00; //subtotal =94.95 |
|
three ways to increment a variable named counter by 1
|
var counter = 1; //counter = 1
counter = counter + 1; //counter now =2 counter += 1; //counter now =3 counter ++; //counter now =4 |
|
string literal
|
value enclosed in quotation marks
|
|
numeric literal
|
string that isn't enclosed in quotation marks
|
|
concatenation operator
|
when + sign is use to add one string to the end of another string, example: "Ray" + "Harris" //"Ray Harris"
"Months: " + 120 //"Months: 120" |
|
How to declare string variables without assigning values to them
|
var zipCode; // declares one variable
var lastName, state, zipCode; //delcare three variables |
|
How to declare string variables and assign values to them
|
var firstName = "Ray", lastname="Harris"; //assigns two string values
var fullName = lastName + ", "+firstName; //fullName is "Harris, Ray" |
|
How to code compound assignment statements with string data
|
var firstName = "Ray", lastName = "Harris";
var fullName = "lastName; //fullName is "Harris" fullName += " , "; //fullname is "Harris, " fullName += firstName; //fullname is "Harris, Ray" |
|
How to code compound assignment statements with mixed data
|
var months = 120;
message = "Months: "; message += months; //message is "Months: 120" |
|
Escape sequences that can be used in strings
|
\n starts a new line in a string
\" Puts a double quotation mark in a string \' Puts a single quotation mark in a string |
|
How escape sequences can be used in a string
|
var message = "A valid variable name\cannot start with a number.";
var message="This isn\'t the right way to do this."; |
|
How to declare Boolean variables and assign values to them
|
var isValid = false; //Boolean value is false
|
|
parseInt(string)
|
method that converts the string that's passed to it to an integer data type and returns that value. If it can't convert the string to an integer, it returns NaN.
|
|
parseFloat(string)
|
method that converts the string that's passed to it to a decimal data type and returns that value. If it can't convert the string to a decimal value, it returns NaN.
|
|
examples that use the parseInt and parseFloat methods
|
var entryA = prompt("Enter any value", 12345.6789);
alert(entryA); // displays 12345.6789 entryA = parseInt(entryA); alert(entryA); //displays 12345 var entryB = prompt ("Enter any value", 12345.8789); alert(entryB); //displays 12345.6789; entryB = parseFloat(entryB); alert(entryB); //displays 12345.6789; var entryC = prompt("Enter any value", "Hello"); alert(entryC); //displays Hello entryC = parseInt (entryC); alerty(entryC); displays Nan |
|
control statements
|
let you control how information is processed in JavaScript
|
|
conditional expression
|
returns a value of true of false based on the result of a comparison between two expressions
|
|
what are the 6 relational operators
|
== equal
!= not equal < less than <== less than or equal > greater than >== greater than or equal |
|
isNaN method
|
determines whether a string value is a valid numeric value
|
|
syntax of global isNaN method
|
isNaN(expression)
|
|
examples of isNaN method
|
isNaN("Harris") //returns true since "Harris" is not a number
isNaN("123.45") //returns false since "123.45" can be converted to a number |
|
compound conditional expression
|
use logical operators to combine conditional expressions
|
|
the logical operators in order of presedence
|
! NOT
&& AND || OR |
|
how does the AND operator work
|
compound expression returns true if both expressions are true
|
|
hows doe the OR operator work
|
the compound expression returns true if either of the expressions are true
|
|
how does the NOT operator work
|
the value of the expression is reversed. for example, !isNaN returns true if the parameter is a number, so isNaN(10) returns false, but !isNaN(10) returns true
|
|
to override the order of precedence when two or more logical operators are used in a conditional statement, what can you use
|
parantheses
|
|
if statements
|
let you control the execution of statements based on the results of conditional expressions. brackets [ ] indicate a portion of the syntax that is optional. example: if (condition-1) {statements} [else if (condition-2) {statements}
|
|
how to code an if clause
|
code the keyword if followed by a conditional expression in parenthesis and a block of one or more statements in braces. if the conditional expression is true, its block of code will be executed and any remaining clauses in the if statement will be skipped over. this will continue until one of the else if expressions is true or they are all false.
|
|
how to code an else clause
|
code the keyword else followed by a block of one or more statements inside braces. this code will only be executed if all the conditional expressions in the if and else if clauses are false. if those expressions are false and there isn't an else clause, the if statement won't execute any code
|
|
how to test whether a boolean variable is false
|
if ( isValid == false) { }
if (!isValid == true) { } if (!sValid) { } |
|
how to write a while loop statement
|
var sumOfNumbers = 0;
var numberOfLoops = 5; var counter = 1; while (counte <= numberOfLoops) { sumOfNumbers += counter; //adds counter to sumOfNumbers counter==; //adds 1 to counter } alert(sumOfNumbers); //displays 15 |
|
what is the difference between a loop and a do-while loop
|
the condition is tested at the end of the loop instead of at the start
|
|
example of do-while statement
|
var sumOfNumbers = 0;
var numberOfLoops = 5; var counter = 1; do { sumOfNumbers += counter; // add counter to SumOfNumbers counter++; //adds 1 to counter } while (counter <= numberOfLoops); alert(sumOfNumbers); //displays 15 |
|
when to use a while loop vs. a do-while loop
|
use do-while when you want to execute the statement in the loop at least once, and the while statement for other types of loops
|
|
while loop that finds the average of a series of numbers
|
var total = 0, count = 0, number;
number = parseFloat (prompt("Enter a number:") ); while ( !isNaN(number) ) { total += number; count++; number = parseFloat ( prompt ("Enter another number or click Cancel to stop:") ); } var average = total / count; alert("The average is: " + average); |
|
what does NaN mean
|
the number isn't valid
|
|
what does !NaN mean
|
the number is valid
|
|
for loop
|
loop that is easier to code when the progress of the loops depends on a value that is incremented each time through loop
|
|
syntax of a for statement and how it breaks down
|
for ( countInitializaton; condition; incrementExpression ) {
statements } -counterInitialization is a counter (or index) -then comes the condition that determines when the loop will end -then comes an expression that determines how the loops should be incremented |
|
a for loop that adds the numbers 1 through 5
|
var sumOfNumbers = 0;
var umberOfLoops = 5; for (counter=1; counter <= numberOfLoops; counter++) { sumOfNumbers += counter; //adds counter to sON } alert (sumOfNumbers); //displays 15 |