Term
What type of language is JavaScript? |
|
Definition
It is a scripting language. |
|
|
Term
JavaScript is a scripting language. What is a scripting language? |
|
Definition
A scripting language is a lightweight programming language. |
|
|
Term
What would be the result of the following code?
<script>
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
</script> |
|
Definition
It will write what is between the <h1> and <p> tags to the browser screen formated accordingly to the respective HTML tags |
|
|
Term
What happens is you use:
document.write
After the document has loaded? |
|
Definition
The whole document will be overwritten. Only use in the HTML output. |
|
|
Term
The alert() function is not much used in JavaScript, however it is useful for...? |
|
Definition
It is often quite handy for trying out code. |
|
|
Term
What will this code do?
<p id="demo">
JavaScript can change the content of an HTML element.
</p>
<script>
function myFunction()
{
x=document.getElementById("demo"); // Find the element
x.innerHTML="Hello JavaScript!"; // Change the content
}
</script> |
|
Definition
It will change the text between the <p> tags to the content in quotes after x.innerHTML
Hello JavaScript! |
|
|
Term
This piece of code tells the computer to do what?
x=document.getElementById("demo"); |
|
Definition
Find the Element
("demo");
document.getElementById("some id")
The "Id" could be anything else. |
|
|
Term
This piece of code tells the computer to do what?
x.innerHTML="Hello JavaScript!"; |
|
Definition
Change the content of the x variable to Hello JavaScript! |
|
|
Term
What does the following code do?
[image] |
|
Definition
Sets up an " if else " condition to where if the user clicks on the image it will change to the alternate image and vice versa... |
|
|
Term
What does the following code do?
[image] |
|
Definition
Creates a text entry field with the id="demo" which is called upon by getElementById and then sets up a " if " condition where if the input is not numeric it will trigger the alert("Not Numeric") notification. |
|
|
Term
What is the difference between JavaScript and Java ? |
|
Definition
They are two completely different languages, in both concept and design. Java (invented by Sun) is a more complex programming language in the same category as C. |
|
|
Term
What is the official name of the JavaScript standard ? |
|
Definition
|
|
Term
Who invented JavaScript ? |
|
Definition
|
|
Term
In what year and what browser did JavaScript first appear ? |
|
Definition
|
|
Term
In what year did the ECMA (a standard association) adopt JavaScript ? |
|
Definition
|
|
Term
|
Definition
European Computer Manufacturers Association
now the ECMA International |
|
|
Term
In an HTML document JavaScript must be placed between which tag ? |
|
Definition
<script>
JavaScript
</script> |
|
|
Term
In what section of an HTML document can JavaScript be placed ? |
|
Definition
The <head> or the <body> sections. |
|
|
Term
JavaScript can be placed in which part(s) of an HTML document ? |
|
Definition
The <head> or the <body> section. |
|
|
Term
It is common practice to place all JavaScript where in an HTML document ? |
|
Definition
All in the <head>section or at the end of the <body> section, this way it is all in one place and does not interfere with the page content. |
|
|
Term
Example of JavaScript in the <head>
What does the following code do ?
[image] |
|
Definition
When the button is clicked it executes the myFunction() script that is in the <head> of the document. This script getElementByID("demo") and changes the text from <p id="demo"> "A Paragraph" to "My First JavaScript Function" |
|
|
Term
Example of JavaScript in the <body>
What does the following code do ?
[image] |
|
Definition
When the button is clicked it executes the myFunction() script that is in the <body> of the document. This script getElementByID("demo") and changes the text from <p id="demo"> "A Paragraph" to "My First JavaScript Function" |
|
|
Term
What does the following code do?
<!DOCTYPE html> <html> <body> <script src="myScript.js"></script> </body> </html> |
|
Definition
Links the "myScript.js" JavaScript file to the HTML document. Example of an External JavaScript file. |
|
|
Term
Is there something wrong with this file named:
myScript.js
<script> function myFunction() { document.getElementById("demo").innerHTML="My First JavaScript Function"; } </script> |
|
Definition
External scripts cannot contain <script> tags. |
|
|
Term
What is JavaScript typically used for in regard to HTML documents ? |
|
Definition
To manipulate HTML elements. |
|
|
Term
How do you access an HTML element from JavaScript
and what attribute do you use in the HTML? |
|
Definition
Tou use the document.getElementById("id") method.
Use the id=" " attribute to identify the HTML element: |
|
|
Term
What does the following code do ?
[image] |
|
Definition
The JavaScript is executed by the web browser. In this case, the browser will access the HTML element with id="demo", and replace its content with innerHTML with "My First JavaScript". |
|
|
Term
JavaScript is a sequence of __________ to be executed by the browser. |
|
Definition
|
|
Term
JavaScript statements are ________ to the browser. |
|
Definition
|
|
Term
What does this JavaScript statement tell the browser to do?
[image] |
|
Definition
Tells the browser to write "Hello Dolly" inside an HTML element with id="demo" |
|
|
Term
What is at the end of all JavaScript statements to separate each one from the next? |
|
Definition
|
|
Term
Is the semicolon at the end of each statement necessary? |
|
Definition
|
|
Term
JavaScript statements are grouped together in ______. |
|
Definition
|
|
Term
Blocks of JavaScript start and end with what? |
|
Definition
Start with a left curly bracket and end with a right curly bracket.
Ex.
{
statement;
statement;
} |
|
|
Term
What is the purpose of grouping JavaScript statements together in blocks? |
|
Definition
So that they execute together. |
|
|
Term
Is JavaScript case sensitive? |
|
Definition
Yes
Ex.
getElementById is not the same as getElementbyId (the first one is correct) |
|
|
Term
Which one is correct:
var name="Hege"; var name = "Hege";
|
|
Definition
Both... JavaScript ignores extra spaces. You can add white space to your script to make it more readable. |
|
|
Term
You can break up a code line within a text string using what? |
|
Definition
A backslash \
Ex.
document.write("Hello \ World!"); |
|
|
Term
What is the difference in how a scripting language (JavaScript) is executed verses how a traditional programming language is executed? |
|
Definition
Scripting code is executed line by line while the browser reads it. With traditional programming, all the code has to be compiled before it can be executed. |
|
|
Term
How do you insert a single line comment in JavaScript? |
|
Definition
Two forward slashes
Ex.
// This is a single line comment
// This is another one |
|
|
Term
How do you insert a multi-line comment in JavaScript? |
|
Definition
Comment starts with a forward slash and an asterisk and ends with an asterisk and a forward slash.
Ex.
/* This is an example of a multi-line comment as it should be formated in JavaScript code. */ |
|
|
Term
Why would you use comments to prevent certian lines of code or statements from being executed? |
|
Definition
Can be useful for debugging. |
|
|
Term
This is an example of doing what?
[image] |
|
Definition
|
|
Term
Think of variables as __________ for storing data. |
|
Definition
|
|
Term
True or False
Variable can have shortVariable can have short names (like x and y) or more descriptive names (age, sum, totalvolume). |
|
Definition
|
|
Term
True or False
Variable names can begin with a letter or a number. |
|
Definition
False
Variable names must begin with a letter. |
|
|
Term
Besides a letter, variable names can begin with what two symbols |
|
Definition
Variable names can also begin with $ and _ |
|
|
Term
Are JavaScript variables case sensitive? |
|
Definition
Yes
Variable names are case sensitive (y and Y are different variables) |
|
|
Term
Besides numbers JavaScript variable can also hold ________. |
|
Definition
Other types of data, like text values (name="John Doe"). |
|
|
Term
In JavaScript a text variable like "John Doe" is called a ______. |
|
Definition
|
|
Term
When you assign a text value to a variable what do you put around it? |
|
Definition
Single or double quotation marks.
Ex.
var name='john doe'
OR
var name2="jane doe" |
|
|
Term
Creating a variable in JavaScript is most often referred to as _________ a variable. |
|
Definition
|
|
Term
What keyword do you use in JavaScript to declare a variable? |
|
Definition
The var keyword.
Ex.
var name="john doe"; |
|
|
Term
What is the case if you declare a variable with no value?
Ex.
var carname; |
|
Definition
|
|
Term
It's a good programming practice to declare all the variables where? |
|
Definition
All in one place at the beginning of your code. |
|
|
Term
You can declare multiple variables in one statement separated by what? |
|
Definition
A comma
Ex.
var name="Doe", age=30, job="carpenter";
OR Multi-line
var name="Doe", age=30, job="carpenter"; |
|
|
Term
Variables declared without a value will have the value _________. |
|
Definition
|
|
Term
Undefined or empty variables may receive a value later by what means. |
|
Definition
The result of a calculation or user input. |
|
|
Term
What will happen if you re-declare a variable?
Ex.
var carname="Volvo"; var carname; |
|
Definition
The variable will still retain the value "Volvo" |
|
|
Term
What do you use to perform arithmetic with variables? |
|
Definition
|
|
Term
JavaScript has dynamic data types. What does this mean? |
|
Definition
Means that the same variable can be used as different types.
Ex.
var x // Now x is undefined var x = 5; // Now x is a Number var x = "John"; // Now x is a String |
|
|
Term
Name 7 JavaScript data types. |
|
Definition
number, string, boolean, array, object, null, undefined |
|
|
Term
What is a JavaScript string? |
|
Definition
A variable which stores a series of characters like "John Doe". |
|
|
Term
Can you use quotes inside a string? |
|
Definition
Yes, as long as they don't match the quotes surrounding the string.
Ex.
var answer="It's alright"; var answer="He is called 'Johnny'"; var answer='He is called "Johnny"'; |
|
|
Term
What is a good way to write extra large or small numbers in JavaScript variables. |
|
Definition
Using scientific (exponential) notation.
Ex.
var y=123e5; // 12300000 var z=123e-5; // 0.00123 |
|
|
Term
What are the only two values that a boolean can have? |
|
Definition
|
|
Term
Booleans are often used for what? |
|
Definition
|
|
Term
What is a JavaScript array? |
|
Definition
A list of values for a variable.
Ex.
var cars=new Array(); cars[0]="Saab"; cars[1]="Volvo"; cars[2]="BMW";
OR a condensed array
var cars=new Array("Saab","Volvo","BMW");
OR a literal array
var cars=["Saab","Volvo","BMW"]; |
|
|
Term
An array index in numbered in what manner? |
|
Definition
They are zero based, meaning that the first item is [0], the second [1], and so on. |
|
|
Term
How is a JavaScript object delimited? |
|
Definition
With curly braces.
Ex.
var person={firstname:"John", lastname:"Doe", id:5566}; |
|
|
Term
Inside the curly braces the objects properties are defined as ____ and _____. |
|
Definition
|
|
Term
The properties in an object are separated by what? |
|
Definition
A comma.
Ex.
var person={firstname:"John", lastname:"Doe", id:5566};
OR
var person={ firstname : "John", lastname : "Doe", id : 5566 }; |
|
|
Term
What are 2 way you can address an object? |
|
Definition
name=person.lastname; name=person["lastname"]; |
|
|
Term
Variables can be emptied by setting the value to what? |
|
Definition
null
Ex.
cars=null; person=null; |
|
|
Term
When you declare a new variable you can declare its type by using what keyword? |
|
Definition
The "new" keyword.
Ex.
var carname=new String; var x= new Number; var y= new Boolean; var cars= new Array; var person= new Object; |
|
|
Term
JavaScript variables are all _______. |
|
Definition
objects
When you declare a variable you create a new object. |
|
|
Term
In JavaScript, an object is data, with __________ and _______. |
|
Definition
|
|
Term
Give an example of object properties. |
|
Definition
car.name=Fiat car.model=500 car.weight=850kg car.color=white |
|
|
Term
Give an example of object methods. |
|
Definition
car.start() car.drive() car.brake() |
|
|
Term
Properties are ______ associated with an object. |
|
Definition
|
|
Term
Methods are _______ that can be performed on an object. |
|
Definition
|
|
Term
In object oriented languages, properties and methods are often called ______ _______. |
|
Definition
|
|
Term
Almost everything in JavaScript is a ______. |
|
Definition
object
Strings, Dates, Arrays, Functions |
|
|
Term
What is this example doing?
person=new Object(); person.firstname="John"; person.lastname="Doe"; person.age=50; person.eyecolor="blue"; |
|
Definition
Creating a new object named "person" and assigning 4 properties to it. |
|
|
Term
What is the syntax for accessing the property of an object? |
|
Definition
|
|
Term
What will the value of x be after the execution of this code:
var message="Hello World!"; var x=message.length; |
|
Definition
|
|
Term
What is the syntax for calling a method on an object? |
|
Definition
|
|
Term
What will be the result of executing the following code?
var message="Hello world!"; var x=message.toUpperCase(); |
|
Definition
|
|
Term
It is common in object oriented languages to use _____ ____ function names. Give example. |
|
Definition
camel-case
someMethod() instead of some_method() |
|
|
Term
What is a JavaScript function? |
|
Definition
A block of code that will be executed when "someone" calls on it.
[image] |
|
|
Term
A function is written as a code block inside what and preceeded by what. |
|
Definition
curly braces { } and preceeded by the function keyword
Ex.
function functionname() { some code to be executed } |
|
|
Term
A function can be called directly when an event occurs such as. |
|
Definition
|
|
Term
A function can be called from where in JavaScript code? |
|
Definition
|
|
Term
When you call a function, you can pass along some values to it, these values are called _________ or __________. |
|
Definition
|
|
Term
How many arguments can you assign to a function? |
|
Definition
You can send as many arguments as you like, separated by commas (,)
Ex.
myFunction(argument1,argument2) |
|
|
Term
The variables and arguments must be in ________ order. |
|
Definition
|
|
Term
What will the following code do?
[image] |
|
Definition
It will alert "Welcome Harry Potter, the Wizard" when the button is clicked. |
|
|
Term
What would the following JavaScript do when run ?
Ex.
"Example".length |
|
Definition
Give an output of ' 7 '
In other words the characters in the string would be counted (including spaces) and provide a numerical output. |
|
|
Term
What would be the output of this example ?
"Example two".length * 2 |
|
Definition
|
|
Term
What will this example do ?
confirm("This Example"); |
|
Definition
It will bring up a ' confirmation ' box with the words ' This Example" with the option buttons of Ok or Cancel. |
|
|
Term
What will this example do ?
prompt("What is your name?"); |
|
Definition
It will bring up a box asking the question ' What is your name? ' and provide a text entry field for the user to answer in. |
|
|
Term
Name three common data types. |
|
Definition
|
|
Term
What are the only two possible values for booleans ? |
|
Definition
|
|
Term
Who is the boolean data type named after ? |
|
Definition
|
|
Term
What does console.log() do ? |
|
Definition
It will take whatever is inside the parentheses and log it to the console below your code.
This is commonly called printing out. |
|
|
Term
Name 5 comparison operators. |
|
Definition
> Greater than
< Less than
<= Less than or equal to
>= Greater than or equal to
=== Equal to
|
|
|
Term
What is an if statement or a conditional statement ? |
|
Definition
The usage of comparisons plus booleans to decide whether a block of code should run. |
|
|
Term
What is the basic syntax of a function in JavaScript ? |
|
Definition
|
|
Term
What does D.R.Y. stand for in programming ? |
|
Definition
|
|
Term
Any time you find yourself typing the same thing, but modifying only one small part, you can probably use what? |
|
Definition
|
|
Term
Can functions have more than one parameter ? |
|
Definition
|
|
Term
What is the basic syntax of a for loop ? |
|
Definition
|
|
Term
Name two ways to increment a number up by "1" |
|
Definition
Provided the variable is i
i + 1
i++ |
|
|
Term
Name two ways to decrement a number by "1" |
|
Definition
Provided the variable is i
i - 1
i-- |
|
|
Term
What is the syntax for incrementing or decrementing by any numerical value ? |
|
Definition
Provided i is the variable and x is the numerical level of increment or decrement.
i += x
i -= x |
|
|
Term
What is the basic syntax of an array ? |
|
Definition
[image]
Note the square brackets [ ] |
|
|
Term
What does Math.random() do in JavaScript ? |
|
Definition
The computer chooses a random number between 0 and 1
Ex.
0.0138295739957
0.9845837659374 |
|
|
Term
What is a while loop ideal for ? |
|
Definition
When you want to use a loop, but you don't know how many times you'll have to execute that loop. |
|
|
Term
What is the basic syntax of a while loop ? |
|
Definition
|
|
Term
What do you put at the end of a long string to wrap to the next line ? |
|
Definition
a backslash ' \ '
Ex.
text ="This is a long string in the code \
editor with a backslash at the \
end of each line that wraps"; |
|
|
Term
What does /*jshint multistr:true */ do ? |
|
Definition
It tells the console to stop worrying about our use of backslash characters for wrapping long lines of text. |
|
|
Term
What is a for loop ideal for ? |
|
Definition
Doing the same task over and over when you know ahead of time how many times you'll have to repeat the loop. |
|
|
Term
What is a ' do ' / ' while ' loop used for ? |
|
Definition
When you want to make sure your loop runs at least one time no matter what. When this is the case, you want a modified while loop called ado /while loop. |
|
|
Term
While loops will continue so long as ? |
|
Definition
The loop will continue so long as the condition being evaluated is true. |
|
|
Term
What is the basic syntax of a do / while loop? |
|
Definition
var condition = false; do { console.log("I'm printed once!"); } while(condition);
|
|
|
Term
The switch statement allows you to present a number of options called _____ ? then check an expression to see if it matches any of them. If there's a match, the program will perform the action for the matching case; if there's no match, it can execute a default option. |
|
Definition
|
|
Term
What is the basic syntax of a switch statement ? |
|
Definition
|
|
Term
Name the 6 comparison operators. |
|
Definition
- === (equals)
- !== (not equal)
- > (greater than)
- >= (greater than or equal to)
- < (less than)
- <= (less than or equal to)
|
|
|
Term
Name the 3 Boolean logical operators and define each. |
|
Definition
- && (Logical AND, returns true if both
expression1 and expression2 are true. Otherwise it returns false).
- || (Logical OR, returns true if
expression3 or expression4 are true, or both are true. Otherwise it returns false).
- ! (Logical negation, returns the boolean that is the opposite of expression5).
|
|
|
Term
What is a heterogeneous array ? |
|
Definition
An array with a mixture of data types.
Ex.
var mix = [42, true, "towel"];
|
|
|
Term
What is a two-dimensional array ? |
|
Definition
One or more arrays nested inside an array.
Ex.
var twoDimensional = [[1, 1], [1, 1]];
|
|
|
Term
|
Definition
Combinations of key-value pairs (like arrays), only their keys don't have to be numbers like 0, 1, or 2: they can be strings and variables. |
|
|
Term
What is the basic syntax of creating an object using object literal notation ? |
|
Definition
var myObj = { type: 'fancy', disposition: 'sunny' }; var emptyObj = {};
|
|
|
Term
What is the basic syntax of creating an object using object constructor ? |
|
Definition
var myObj = new Object();
You can add keys to your object after you've created it in two ways:
myObj["name"] = "Charlie";
myObj.name = "Charlie";
|
|
|
Term
What are the two ways of creating an object ? |
|
Definition
object literal notation
and
object constructor |
|
|
Term
What is the basic syntax of a for / in loop ? |
|
Definition
for (var something in object) { }
|
|
|