JAVASCRIPT Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Where does JavaScript run?

A

In the browser, no need for a development environment.

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

What is built-in the browser to run JavaScript code?

A

The JavaScript console.

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

How do you open the JavaScript console?

A

ctrl+shft+J

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

How do you clear the console?

A

by pressing the circular icon with the bar running through it.

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

What is a line of JavaScript code called?

A

A JavaScript statement.

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

How to bring up a pop-up box with a statement on it?

A

alert();

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

How to bring up the previous command on the console?

A

use the up arrow.

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

Code for a dialog-box with the words “hi” …

A

alert(“hi”);

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

Code to send a message to the console with the word “Hello” …

A

console.log(“Hello”);

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

Code to send the text “Hi” to the webpage you’re on …

A

document.write(“Hi”);

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

How do you to the next line in the console without entering your current line of code?

A

shft + return

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

Code to write an < H1 > with the text “Fuck You” to the current webpage you’re on …

A

document.write( “ < h1 > Fuck You < / h1 > “ );

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

How does code run?

A

line by line

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

Where do you place JavaScript code?

A

In a seperate file, but in the same folder of your html, much like a CSS file.

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

What executes JavaScript code?

A

The JavaScript engine built into the browser.

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

What extension do JavaScript files have?

A

.js

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

Where are JavaScript links usually placed in HTML files?

A

Just before the ending < body > tag.

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

Code for a link from an html file to a JavaScript file named script.js which is in a file named js …

A

< script src = “ js / script.js “ > < / script >

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

Can you link more than one JavaScript file in your html file?

A

YES, YES a thousand times YES, ALREADY!!!

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

Where are JavaScript errors logged?

A

In the JavaScript console.

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

What info will be listed on the error line in the console?

A

the file and line of error

22
Q

Is JavaScript case sensitive?

A

YES

23
Q

How do you write a JavaScript comment?

A

// till eol, end of line

/* mutline

like

this */

24
Q

What are the three ways you can declare a JavaScript variable?

A

var

let

const

25
Q

Declare a variable named score …

A

var score;

const score;

let score;

26
Q

Declare and assign a value, 0, to the variable named score …

A

var score = 0;

let score = 0;

const score = 0;

27
Q

What is meant by “reassigning a variable”?

A

It is when you overwrite a value in a variable with a new value.

var score = 0;

score = 1;

notice you don’t have to write var twice, which is nice.

28
Q

Which type of variable can you not use to reassign a value to?

A

const

29
Q

What are some of the rules for naming variables?

A
  1. Variable names cannot start with a number. (9lives, no good).
  2. Names can only contain letters, numbers, and the $ and _ characters.
  3. Use camelCase for multiWord variable names.
  4. Make variable names meaningful.
  5. Don’t use KW’s.
30
Q

Code an example of the addition assignment operator …

A

var score = 5;

score += 10;

console.log(score);

what would score be now?

15

31
Q

Code showing how you can use variable names to add up values just as you would use numbers …

A

var score = 15;

var bonusPoints = 100;

var finalScore = score + bonusPoints;

document.write(finalScore);

115

32
Q

What can one say about spacing around the = in JavaScript?

A

_ = _

33
Q

How do you list strings?

A

Use double quotation marks “some string”.

34
Q

How would you use html in a string?

A

If you’re using html in a string and have to use double quotes, use single quotes outside your string …

const htmlSnippet = ‘ < h1 class = “ headline “ > ‘

35
Q

What is an escape character and how would you use it?

A

\ is the escape character and you use it before a character you want to use literally and not code-wise, i.e. …

const message = ‘ I'm a programmer ! ‘ ;

36
Q

How to use an escape character when dealing with multi-line strings?

A

const multiLine = “ Hello , students \

Welcome to JS

37
Q

Code to find the length of a string …

A

const passPhrase = “Open Sesame”;

console.log(passPhrase.length);

11

38
Q

In JavaScript what is an action you can take called?

A

this one is called a method

39
Q

Code for making a string all lower case …

A

const passPhrase = “I have spoken”;

console.log(“ passPhrase.toLowerCase());

>i have spoken

40
Q

Code to list a string to all upper case …

A

const passPhrase = “i have spoken”;

console.log(passPhrase.toUpperCase());

>I HAVE SPOKEN

41
Q

How to code for a question dialog box and to get a response to use somehow …

A

use the prompt() …

prompt(“What is your major malfunction?”);

42
Q

How would you use the prompt to save some value …

A

const name = prompt(“What is your name?’);

console.log(name);

or

alert(name);

or

document.write( “ < h1 > name < / h1 > “ );

43
Q

What is the process called when combining two or more strings together?

A

this one is called string concatenation

44
Q

How to code to concatenate two string together?

A

“My favorite” + “Movies”;

My favorite Movies

45
Q

How to code using a prompt and a string …

A

const name = prompt(“What is your name?”);

const message = “ Hello “ + name;

console.log(message);

or

alert(message);

or

document.write(message);

46
Q

Code for using a template literal …

A

const name = prompt(“What is your name?”);

const message = Hello, ${name};

console.log(message);

47
Q

What are some true “things” about template literals?

A
  1. With template literals you don’t have to worry about spaces or escape characters.
  2. With template literals you can write multi-line strings w/out any special characters, no back-slash for example.
48
Q

How to display a value of a string onto a page …

A

It’s a two step process:

  1. Select the html element where you want your content to appear:
    document. querySelector(‘main’);
  2. What content you want to insert into that element.
49
Q

Code using a querySelector …

A

const message = “What the fuck … over”;

document.querySelector(‘main’).innerHTML = message;

50
Q

Code using some template literals using Great Gatsby …

A

const title = “ The Great Gatsby “;

const price = “ 14.99 “;

const book = ${title} : \$\${price};

51
Q
A