Terms Flashcards

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
Q

What is at the end of all JavaScript statements to separate each one from the next?

A

A semicolon ;

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

Is the semicolon at the end of each statement necessary?

A

No, it’s optional

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

JavaScript statements are grouped together in ______.

A

blocks

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

Blocks of JavaScript start and end with what?

A

Start with a left curly bracket and end with a right curly bracket.

Ex.

{

statement;

statement;

}

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

What is the purpose of grouping JavaScript statements together in blocks?

A

So that they execute together.

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

Is JavaScript case sensitive?

A

Yes

Ex.

getElementById is not the same as getElementbyId (the first one is correct)

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

Which one is correct:

var name="Hege";
var name = "Hege";
A

Both… JavaScript ignores extra spaces. You can add white space to your script to make it more readable.

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

You can break up a code line within a text string using what?

A

A backslash \

Ex.

document.write(“Hello \
World!”);

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

What is the difference in how a scripting language (JavaScript) is executed verses how a traditional programming language is executed?

A

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.

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

How do you insert a single line comment in JavaScript?

A

Two forward slashes

Ex.

// This is a single line comment

// This is another one

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

How do you insert a multi-line comment in JavaScript?

A

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. */

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

Why would you use comments to prevent certian lines of code or statements from being executed?

A

Can be useful for debugging.

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

Think of variables as __________ for storing data.

A

containers

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

Variable can have shortVariable can have short names (like x and y) or more descriptive names (age, sum, totalvolume).

A

True

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

True or False

Variable names can begin with a letter or a number.

A

False

Variable names must begin with a letter.

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

Besides a letter, variable names can begin with what two symbols

A

Variable names can also begin with $ and _

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

Are JavaScript variables case sensitive?

A

Yes

Variable names are case sensitive (y and Y are different variables)

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

Besides numbers JavaScript variable can also hold ________.

A

Other types of data, like text values (name=”John Doe”).

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

In JavaScript a text variable like “John Doe” is called a ______.

A

string

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

When you assign a text value to a variable what do you put around it?

A

Single or double quotation marks.

Ex.

var name=’john doe’

 OR

var name2=”jane doe”

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

Creating a variable in JavaScript is most often referred to as _________ a variable.

A

declaring

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

What keyword do you use in JavaScript to declare a variable?

A

The var keyword.

Ex.

var name=”john doe”;

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

What is the case if you declare a variable with no value?

Ex.

var carname;

A

The variable is empty

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

It’s a good programming practice to declare all the variables where?

A

All in one place at the beginning of your code.

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

You can declare multiple variables in one statement separated by what?

A

A comma

Ex.

var name=”Doe”, age=30, job=”carpenter”;

  OR Multi-line
var name="Doe",
age=30,
job="carpenter";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

Variables declared without a value will have the value _________.

A

undefined

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

Undefined or empty variables may receive a value later by what means.

A

The result of a calculation or user input.

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

What will happen if you re-declare a variable?

Ex.

var carname="Volvo"; 
var carname;
A

The variable will still retain the value “Volvo”

53
Q

What do you use to perform arithmetic with variables?

A

Operators like + , - , =

54
Q

JavaScript has dynamic data types. What does this mean?

A

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
Q

Name 7 JavaScript data types.

A

number, string, boolean, array, object, null, undefined

56
Q

What is a JavaScript string?

A

A variable which stores a series of characters like “John Doe”.

57
Q

Can you use quotes inside a string?

A

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
Q

What is a good way to write extra large or small numbers in JavaScript variables.

A

Using scientific (exponential) notation.

Ex.

var y=123e5;      // 12300000
var z=123e-5;     // 0.00123
59
Q

What are the only two values that a boolean can have?

A

true or false

60
Q

Booleans are often used for what?

A

Conditional testing

61
Q

What is a JavaScript array?

A

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
Q

An array index in numbered in what manner?

A

They are zero based, meaning that the first item is [0], the second [1], and so on.

63
Q

How is a JavaScript object delimited?

A

With curly braces.

Ex.

var person={firstname:”John”, lastname:”Doe”, id:5566};

64
Q

Inside the curly braces the objects properties are defined as ____ and _____.

A

( name : value )

65
Q

The properties in an object are separated by what?

A

A comma.

Ex.

var person={firstname:”John”, lastname:”Doe”, id:5566};

 OR
var person={
firstname : "John",
lastname  : "Doe",
id        :  5566
};
66
Q

What are 2 way you can address an object?

A

name=person.lastname;

name=person[“lastname”];

67
Q

Variables can be emptied by setting the value to what?

A

null

Ex.

cars=null;
person=null;

68
Q

When you declare a new variable you can declare its type by using what keyword?

A

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
Q

JavaScript variables are all _______.

A

objects

When you declare a variable you create a new object.

70
Q

In JavaScript, an object is data, with __________ and _______.

A

properties and methods

71
Q

Give an example of object properties.

A

car. name=Fiat
car. model=500
car. weight=850kg
car. color=white

72
Q

Give an example of object methods.

A

car. start()
car. drive()
car. brake()

73
Q

Properties are ______ associated with an object.

A

values

74
Q

Methods are _______ that can be performed on an object.

A

actions

75
Q

In object oriented languages, properties and methods are often called ______ _______.

A

object members

76
Q

Almost everything in JavaScript is a ______.

A

object

Strings, Dates, Arrays, Functions

77
Q

What is this example doing?

person=new Object();

person. firstname=”John”;
person. lastname=”Doe”;
person. age=50;
person. eyecolor=”blue”;

A

Creating a new object named “person” and assigning 4 properties to it.

78
Q

What is the syntax for accessing the property of an object?

A

objectName.propertyName

79
Q

What will the value of x be after the execution of this code:

var message="Hello World!";
var x=message.length;
A

12

80
Q

What is the syntax for calling a method on an object?

A

objectName.methodName()

81
Q

What will be the result of executing the following code?

var message="Hello world!";
var x=message.toUpperCase();
A

HELLO WORLD!

82
Q

It is common in object oriented languages to use _____ ____ function names. Give example.

A

camel-case

someMethod() instead of some_method()

83
Q

What is a JavaScript function?

A

A block of code that will be executed when “someone” calls on it.

84
Q

A function is written as a code block inside what and preceeded by what.

A

curly braces { } and preceeded by the function keyword

Ex.

function functionname()
{
some code to be executed
}
85
Q

A function can be called directly when an event occurs such as.

A

A user clicks a button.

86
Q

A function can be called from where in JavaScript code?

A

Anywhere

87
Q

When you call a function, you can pass along some values to it, these values are called _________ or __________.

A

arguments or parameters

88
Q

How many arguments can you assign to a function?

A

You can send as many arguments as you like, separated by commas (,)

Ex.

myFunction(argument1,argument2)

89
Q

The variables and arguments must be in ________ order.

A

expected

90
Q

What would the following JavaScript do when run ?

Ex.

“Example”.length

A

Give an output of ‘ 7 ‘

In other words the characters in the string would be counted (including spaces) and provide a numerical output.

91
Q

What would be the output of this example ?

“Example two”.length * 2

A

22

92
Q

What will this example do ?

confirm(“This Example”);

A

It will bring up a ‘ confirmation ‘ box with the words ‘ This Example” with the option buttons of Ok or Cancel.

93
Q

What will this example do ?

prompt(“What is your name?”);

A

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
Q

Name three common data types.

A

Numbers

Strings

Booleans

95
Q

What are the only two possible values for booleans ?

A

True or False

96
Q

Who is the boolean data type named after?

A

George Boole

97
Q

What does console.log() do ?

A

It will take whatever is inside the parentheses and log it to the console below your code.

This is commonly called printing out.

98
Q

Name 5 comparison operators.

A

> Greater than
< Less than
= Greater than or equal to
=== Equal to

99
Q

What is an if statement or a conditional statement?

A

The usage of comparisons plus booleans to decide whether a block of code should run.

100
Q

What is the basic syntax of a function in JavaScript?

A

function name (parameter) {//code;}

101
Q

What does D.R.Y. stand for in programming?

A

Don’t Repeat Yourself

102
Q

Any time you find yourself typing the same thing, but modifying only one small part, you can probably use what?

A

A function

103
Q

Can functions have more than one parameter?

A

Yes

104
Q

What is the basic syntax of a for loop?

A

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
Q

ame two ways to increment a number up by “1”

A

Provided the variable is i

i + 1

i++

106
Q

Name two ways to decrement a number by “1”

A

i - 1

i–

107
Q

What is the syntax for incrementing or decrementing by any numerical value ?

A

Provided i is the variable and x is the numerical level of increment or decrement.

i += x

i -= x

108
Q

What is the basic syntax of an array ?

A

var array = [];

Note the square brackets

109
Q

What does Math.random() do in JavaScript ?

A

The computer chooses a random number between 0 and 1

Ex.

  1. 0138295739957
  2. 9845837659374
110
Q

What is a while loop ideal for?

A

When you want to use a loop, but you don’t know how many times you’ll have to execute that loop.

111
Q

What is the basic syntax of a while loop?

A

while(condition){ // Do something! }

112
Q

What do you put at the end of a long string to wrap to the next line?

A

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
Q

What does /*jshint multistr:true */ do ?

A

It tells the console to stop worrying about our use of backslash characters for wrapping long lines of text.

114
Q

What is a for loop ideal for ?

A

Doing the same task over and over when you know ahead of time how many times you’ll have to repeat the loop.

115
Q

What is a ‘ do ‘ / ‘ while ‘ loop used for ?

A

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
Q

While loops will continue so long as ?

A

The loop will continue so long as the condition being evaluated is true.

117
Q

What is the basic syntax of a do / while loop?

A

var condition = false; do { console.log(“I’m printed once!”); } while(condition);

118
Q

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.

A

case(s)

119
Q

What is the basic syntax of a switch statement ?

A
switch(expression) {
    case n:
        code block
        break;
    case n:
        code block
        break;
    default:
        default code block
}
120
Q

Name the 6 comparison operators.

A
===  (equals)
!==   (not equal)
>      (greater than)
>=    (greater than or equal to) 
<      (less than)
<=    (less than or equal to)
121
Q

Name the 3 Boolean logical operators and define each.

A

&& (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
Q

What is a heterogeneous array?

A

An array with a mixture of data types.

Ex.

var mix = [42, true, “towel”];

123
Q

What is a two-dimensional array ?

A

One or more arrays nested inside an array.

Ex.

var twoDimensional = [[1, 1], [1, 1]];

124
Q

What is an object?

A

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
Q

What is the basic syntax of creating an object using object literal notation?

A

var myObj = { type: ‘fancy’, disposition: ‘sunny’ }; var emptyObj = {};

126
Q

What is the basic syntax of creating an object using object constructor ?

A
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
Q

What are the two ways of creating an object ?

A

Literal object notation and object constructor

128
Q

What is the basic syntax of a for / in loop ?

A

for (var something in object) { // Do something }