Terms Flashcards

(128 cards)

1
Q

What type of language is JavaScript?

A

It is a scripting language.

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

JavaScript is a scripting language. What is a scripting language?

A

A scripting language is a lightweight programming language.

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

What would be the result of the following code?

<h1>This is a heading</h1>

<p>This is a paragraph.</p>

A

It will write what is between the <h1> and <p> tags to the browser screen formated accordingly to the respective HTML tags

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

What happens is you use:

document.write

After the document has loaded?

A

The whole document will be overwritten. Only use in the HTML output.

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

The alert() function is not much used in JavaScript, however it is useful for…?

A

It is often quite handy for trying out code.

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

What will this code do?

<p>

JavaScript can change the content of an HTML element.

</p>

A

It will change the text between the <p> tags to the content in quotes after x.innerHTML

Hello JavaScript!

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

This piece of code tells the computer to do what?

x=document.getElementById(“demo”);

A

Find the Element

(“demo”);

document.getElementById(“some id”)

The “Id” could be anything else.

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

This piece of code tells the computer to do what?

x.innerHTML=”Hello JavaScript!”;

A

Change the content of the x variable to Hello JavaScript!

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

What is the difference between JavaScript and Java ?

A

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.

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

What is the official name of the JavaScript standard ?

A

ECMA-262

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

Who invented JavaScript ?

A

Brendan Eich

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

In what year and what browser did JavaScript first appear ?

A

1995

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

In what year did the ECMA (a standard association) adopt JavaScript ?

A

1997

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

Who is the ECMA ?

A

European Computer Manufacturers Association

now the ECMA International

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

In an HTML document JavaScript must be placed between which tag ?

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

In what section of an HTML document can JavaScript be placed ?

A

The or the sections.

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

JavaScript can be placed in which part(s) of an HTML document ?

A

The or the sections.

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

It is common practice to place all JavaScript where in an HTML document ?

A

All in the section or at the end of the section, this way it is all in one place and does not interfere with the page content.

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

What does the following code do?

<!DOCTYPE html>

A

Links the “myScript.js” JavaScript file to the HTML document. Example of an External JavaScript file.

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

Is there something wrong with this file named:

myScript.js

A

External scripts cannot contain

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

What is JavaScript typically used for in regard to HTML documents ?

A

To manipulate HTML elements.

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

How do you access an HTML element from JavaScript

and what attribute do you use in the HTML?

A

To use the document.getElementById(“id”) method.

Use the id=” “ attribute to identify the HTML element:

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

JavaScript is a sequence of __________ to be executed by the browser.

A

statements

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

JavaScript statements are ________ to the browser.

A

commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is at the end of all JavaScript statements to separate each one from the next?
A semicolon ;
26
Is the semicolon at the end of each statement necessary?
No, it's optional
27
JavaScript statements are grouped together in ______.
blocks
28
Blocks of JavaScript start and end with what?
Start with a left curly bracket and end with a right curly bracket. Ex. { statement; statement; }
29
What is the purpose of grouping JavaScript statements together in blocks?
So that they execute together.
30
Is JavaScript case sensitive?
Yes Ex. getElementById is not the same as getElementbyId (the first one is correct)
31
Which one is correct: ``` var name="Hege"; var name = "Hege"; ```
Both... JavaScript ignores extra spaces. You can add white space to your script to make it more readable.
32
You can break up a code line within a text string using what?
A backslash \ Ex. document.write("Hello \ World!");
33
What is the difference in how a scripting language (JavaScript) is executed verses how a traditional programming language is executed?
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.
34
How do you insert a single line comment in JavaScript?
Two forward slashes Ex. // This is a single line comment // This is another one
35
How do you insert a multi-line comment in JavaScript?
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. */
36
Why would you use comments to prevent certian lines of code or statements from being executed?
Can be useful for debugging.
37
Think of variables as __________ for storing data.
containers
38
Variable can have shortVariable can have short names (like x and y) or more descriptive names (age, sum, totalvolume).
True
39
True or False Variable names can begin with a letter or a number.
False Variable names must begin with a letter.
40
Besides a letter, variable names can begin with what two symbols
Variable names can also begin with $ and _
41
Are JavaScript variables case sensitive?
Yes Variable names are case sensitive (y and Y are different variables)
42
Besides numbers JavaScript variable can also hold ________.
Other types of data, like text values (name="John Doe").
43
In JavaScript a text variable like "John Doe" is called a ______.
string
44
When you assign a text value to a variable what do you put around it?
Single or double quotation marks. Ex. var name='john doe' OR var name2="jane doe"
45
Creating a variable in JavaScript is most often referred to as _________ a variable.
declaring
46
What keyword do you use in JavaScript to declare a variable?
The var keyword. Ex. var name="john doe";
47
What is the case if you declare a variable with no value? Ex. var carname;
The variable is empty
48
It's a good programming practice to declare all the variables where?
All in one place at the beginning of your code.
49
You can declare multiple variables in one statement separated by what?
A comma Ex. var name="Doe", age=30, job="carpenter"; OR Multi-line ``` var name="Doe", age=30, job="carpenter"; ```
50
Variables declared without a value will have the value _________.
undefined
51
Undefined or empty variables may receive a value later by what means.
The result of a calculation or user input.
52
What will happen if you re-declare a variable? Ex. ``` var carname="Volvo"; var carname; ```
The variable will still retain the value "Volvo"
53
What do you use to perform arithmetic with variables?
Operators like + , - , =
54
JavaScript has dynamic data types. What does this mean?
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 ```
55
Name 7 JavaScript data types.
number, string, boolean, array, object, null, undefined
56
What is a JavaScript string?
A variable which stores a series of characters like "John Doe".
57
Can you use quotes inside a string?
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"'; ```
58
What is a good way to write extra large or small numbers in JavaScript variables.
Using scientific (exponential) notation. Ex. ``` var y=123e5; // 12300000 var z=123e-5; // 0.00123 ```
59
What are the only two values that a boolean can have?
true or false
60
Booleans are often used for what?
Conditional testing
61
What is a JavaScript array?
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"];
62
An array index in numbered in what manner?
They are zero based, meaning that the first item is [0], the second [1], and so on.
63
How is a JavaScript object delimited?
With curly braces. Ex. var person={firstname:"John", lastname:"Doe", id:5566};
64
Inside the curly braces the objects properties are defined as ____ and _____.
( name : value )
65
The properties in an object are separated by what?
A comma. Ex. var person={firstname:"John", lastname:"Doe", id:5566}; OR ``` var person={ firstname : "John", lastname : "Doe", id : 5566 }; ```
66
What are 2 way you can address an object?
name=person.lastname; | name=person["lastname"];
67
Variables can be emptied by setting the value to what?
null Ex. cars=null; person=null;
68
When you declare a new variable you can declare its type by using what keyword?
The "new" keyword. Ex. ``` var carname=new String; var x= new Number; var y= new Boolean; var cars= new Array; var person= new Object; ```
69
JavaScript variables are all _______.
objects When you declare a variable you create a new object.
70
In JavaScript, an object is data, with __________ and _______.
properties and methods
71
Give an example of object properties.
car. name=Fiat car. model=500 car. weight=850kg car. color=white
72
Give an example of object methods.
car. start() car. drive() car. brake()
73
Properties are ______ associated with an object.
values
74
Methods are _______ that can be performed on an object.
actions
75
In object oriented languages, properties and methods are often called ______ _______.
object members
76
Almost everything in JavaScript is a ______.
object Strings, Dates, Arrays, Functions
77
What is this example doing? person=new Object(); person. firstname="John"; person. lastname="Doe"; person. age=50; person. eyecolor="blue";
Creating a new object named "person" and assigning 4 properties to it.
78
What is the syntax for accessing the property of an object?
objectName.propertyName
79
What will the value of x be after the execution of this code: ``` var message="Hello World!"; var x=message.length; ```
12
80
What is the syntax for calling a method on an object?
objectName.methodName()
81
What will be the result of executing the following code? ``` var message="Hello world!"; var x=message.toUpperCase(); ```
HELLO WORLD!
82
It is common in object oriented languages to use _____ ____ function names. Give example.
camel-case someMethod() instead of some_method()
83
What is a JavaScript function?
A block of code that will be executed when "someone" calls on it.
84
A function is written as a code block inside what and preceeded by what.
curly braces { } and preceeded by the function keyword Ex. ``` function functionname() { some code to be executed } ```
85
A function can be called directly when an event occurs such as.
A user clicks a button.
86
A function can be called from where in JavaScript code?
Anywhere
87
When you call a function, you can pass along some values to it, these values are called _________ or __________.
arguments or parameters
88
How many arguments can you assign to a function?
You can send as many arguments as you like, separated by commas (,) Ex. myFunction(argument1,argument2)
89
The variables and arguments must be in ________ order.
expected
90
What would the following JavaScript do when run ? Ex. "Example".length
Give an output of ' 7 ' In other words the characters in the string would be counted (including spaces) and provide a numerical output.
91
What would be the output of this example ? "Example two".length * 2
22
92
What will this example do ? confirm("This Example");
It will bring up a ' confirmation ' box with the words ' This Example" with the option buttons of Ok or Cancel.
93
What will this example do ? prompt("What is your name?");
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.
94
Name three common data types.
Numbers Strings Booleans
95
What are the only two possible values for booleans ?
True or False
96
Who is the boolean data type named after?
George Boole
97
What does console.log() do ?
It will take whatever is inside the parentheses and log it to the console below your code. This is commonly called printing out.
98
Name 5 comparison operators.
> Greater than < Less than = Greater than or equal to === Equal to
99
What is an if statement or a conditional statement?
The usage of comparisons plus booleans to decide whether a block of code should run.
100
What is the basic syntax of a function in JavaScript?
function name (parameter) {//code;}
101
What does D.R.Y. stand for in programming?
Don't Repeat Yourself
102
Any time you find yourself typing the same thing, but modifying only one small part, you can probably use what?
A function
103
Can functions have more than one parameter?
Yes
104
What is the basic syntax of a for loop?
for (i=0; i<11; i++) {//code;} Basically, while the condition above is true it will run the code in curly brackets and increment by 1 each time until i is no longer less than 11.
105
ame two ways to increment a number up by "1"
Provided the variable is i i + 1 i++
106
Name two ways to decrement a number by "1"
i - 1 i--
107
What is the syntax for incrementing or decrementing by any numerical value ?
Provided i is the variable and x is the numerical level of increment or decrement. i += x i -= x
108
What is the basic syntax of an array ?
var array = []; Note the square brackets
109
What does Math.random() do in JavaScript ?
The computer chooses a random number between 0 and 1 Ex. 0. 0138295739957 0. 9845837659374
110
What is a while loop ideal for?
When you want to use a loop, but you don't know how many times you'll have to execute that loop.
111
What is the basic syntax of a while loop?
while(condition){ // Do something! }
112
What do you put at the end of a long string to wrap to the next line?
a backslash ' \ ' Ex. text ="This is a long string in the code \ editor with a backslash at the \ end of each line that wraps";
113
What does /*jshint multistr:true */ do ?
It tells the console to stop worrying about our use of backslash characters for wrapping long lines of text.
114
What is a for loop ideal for ?
Doing the same task over and over when you know ahead of time how many times you'll have to repeat the loop.
115
What is a ' do ' / ' while ' loop used for ?
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.
116
While loops will continue so long as ?
The loop will continue so long as the condition being evaluated is true.
117
What is the basic syntax of a do / while loop?
var condition = false; do { console.log("I'm printed once!"); } while(condition);
118
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.
case(s)
119
What is the basic syntax of a switch statement ?
``` switch(expression) { case n: code block break; case n: code block break; default: default code block } ```
120
Name the 6 comparison operators.
``` === (equals) !== (not equal) > (greater than) >= (greater than or equal to) < (less than) <= (less than or equal to) ```
121
Name the 3 Boolean logical operators and define each.
&& (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).
122
What is a heterogeneous array?
An array with a mixture of data types. Ex. var mix = [42, true, "towel"];
123
What is a two-dimensional array ?
One or more arrays nested inside an array. Ex. var twoDimensional = [[1, 1], [1, 1]];
124
What is an object?
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.
125
What is the basic syntax of creating an object using object literal notation?
var myObj = { type: 'fancy', disposition: 'sunny' }; var emptyObj = {};
126
What is the basic syntax of creating an object using object constructor ?
``` 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";
127
What are the two ways of creating an object ?
Literal object notation and object constructor
128
What is the basic syntax of a for / in loop ?
for (var something in object) { // Do something }