Intro Flashcards

1
Q

What is the syntax to include JS in your HTML and where in the file can it be placed? And to link an external JS file either local in the same folder or a specified folder, or a URL (reason is it’s easier to read/maintain & load faster with cached JS files)?

A

script tags in head or body or both; script src=”something.js” or “/something/something.js” or “https://something.com/something.js” tags (preferably in head).

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

What is the common JS syntax/code to change or add to the HTML element content?

A

document.getElementById(‘demo’).innerHTML = ‘Hello World’;

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

JS can change HTML attributes: What would the HTML and the JS look like for having a light bulb image with a button on the left & right to turn it on/off by changing the image from gray to colored? First way is all done in HTML, second way is utilizing JS.

A

HTML will have img id=”lightBulb” src=”bulbOff.jpg” & one button onclick=”document.getElementById(‘lightBulb’).src=’bulbOn.jpg’ “ & another will be onclick=”document.getElementById(‘lightBulb’).src=’bulbOff.jpg’ “

OR

HTML will have img id=”lightBulb” src=”bulbOff.jpg” & one button onclick=”lightOn” & another will be onclick=”lightOff”.

The JS will have lightOn function with content document.getElementById(‘lightBulb’).src=’bulbOn.jpg’; & lightOff function with content document.getElementById(‘lightBulb’).src=’bulbOff.jpg’;

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

JS can change HTML attributes: What would the HTML look like for a sentence in a paragraph that can increase it’s font size by the click of a button? And then another button to hide (or show) it all together? Can also do this by utilizing JS instead of writing the script in the HTML.

A

Paragraph tag with a sentence string as the content and id=”demo”.

A button below it saying click me as the content will have the DOM event onclick=”document.getElementById(‘demo’).style.fontSize=’35px’ “.

Another button to hide it will have the DOM event onclick=”document.getElementById(‘demo’).style.display=’none’ “ or ‘block’.

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

What is a Javascript function?

A

A block of reusable Javascript code that can be executed when invoked. It can be self invoked by writing its name with parentheses as a statement outside of the function somewhere or called when an event occurs such as clicking a button.

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

What are some (4) of the different ways JS can display/print data?

A

the “innerHTML” property can set or overwrite the specified HTML element content

document. write() used only for testing will write into the HTML output position will be where you place it in the HTML file or if its in JS it will be at the top of everything in ascending order, or if it is called as part of a function it will overwrite the current HTML to display something new
window. alert() will display in an alert box
console. log() used for debugging will display in the console

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

What are JS statements? And what are its 5 different components?

A

The list of instructions to be executed by the browser (separated by semicolons)

ex-
var x;
var y = 2;
x = 1;
z = x + y;

Values (variable & literal), operators, expressions, keywords, and comments.

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

What is the purpose of variables, how do we declare them, and how do we assign values to them? What is their value after they are declared without anything assigned?

A

They’re used to store data values; declare using the “var” keyword; use “=” to assign values to them. Their value w/o anything assigned is undefined. (We can use the var keyword just once for multiple identifiers with their individual values in one statement)

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

What are the different types of operators? Explain.

A

Arithmetic operators (+, -, *, /, %, **, ++, –); assignment operators (aslo serve as string operators: =, +=, -=, *=, /=, %=); comparison (=== or > or <= or !=); logical (&& or ! or ||); type (typeof, which returns the type of a variable… or instanceof, which returns true if an object is an instance of an object type).

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

What is a JS expression?

A

Any combination of values (can even be strings), variables, and operators, which computes to a value.

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

What are JS keywords?

A

Used to identify action to be performed (such as “var” tells the browser to create a variable).

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

What is the syntax for comments in JS? in HTML?

A

Two forward slashes before a specific line; or, a forward slash+asterisk before desired spot and after an asterisk+forward slash.

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

What are JS identifiers? And their rules?

A

Names used to name variables, keywords, functions, and labels. First character must be a letter, underscore, or dollar sign. (Numbers can come after)

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

What does lower camel case look like? What does upper camel case look like and what is another name for this?

A

lowerCamelCase; UpperCamelCase - pascal case.

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

If you put a number in quotes, what happens to the rest of the numbers in the expression after it (in terms of type)? What happens to the output type when any string is being calculated with a number?

A

The numbers after it will also be treated as strings and concatenated instead of mathematically calculated. Any time a string is in an expression with a number, the output will be a string.

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

What is the purpose of HTML? CSS? JS?

A
  1. HTML to define the content of web pages
    1. CSS to specify the layout of web pages
    2. JavaScript to program the behavior of web pages
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

When was JavaScript invented? By who? And what was its official name?

A

By Brendan Eich in 1995. ECMAScript.

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

Use escape characters to alert We are “Vikings”

A

Backslash before each quotation mark that you wish to display; alert(“We are "Vikings"”);

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

What are the two best places to break a line of code?

A

After an operator or a comma.

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

What are the different data types?

A

Numbers, strings, objects, booleans, arrays, undefined

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

What is the term for the pieces inside an array? What is the term to refer to it’s numerical position?

A

Items. Index number.

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

What is the term for the pieces inside an object which are separated by commas and written with quotations? What is the term for the first portion of that, and then the second portion which comes after the colon?

A

Properties. Name: value (name:value pairs).

23
Q

What is the value of a variable without a value?

A

Undefined.

24
Q

What is the data type of null?

A

An object.

25
Q

What are the different ways to empty a variable?

A

Set to undefined, null (this is to empty objects because the data type will remain an object), or empty quotations.

26
Q

What is the value of empty quotations? of null? of undefined?

A

Legal (blank) value; no value; no value.

27
Q

What is a primitive data value?

A

A single simple data value with no additional properties or methods (string, number, boolean, undefined).

28
Q

What is a complex data value?

A

typeof will return as a function or object (an array or null is also considered an object type).

29
Q

What are function parameters and function arguments? How do they behave inside the function?

A

Parameters are the placeholders found in parentheses after the function name, which accept incoming arguments (values) when the function is invoked. Inside the function, the parameters (stored with arguments) behave like local variables.

30
Q

What are two ways to access properties from objects?

A

objectname.propertyname or objectname[“propertyname”]

31
Q

What happens when you declare a variable with the keyword “new”?

A

The variable gets created as an object.

32
Q

What are events?

A

Things that can happen to HTML elements as a result of some action the user makes or the browser makes.

33
Q

What is hoisting?

A

Variable declarations written in JavaScript are moved to the top of the scope.

34
Q

What is variable initialization?

A

When a variable is defined it is initialized.

35
Q

How do you check whether a value is not a number?

A

isNan()

36
Q

What is a JavaScript closure?

A

An inner function that has access to the scope (variables; parameters) of its outer (enclosing) function, its own scope, and the global scope; though, it cannot call its outer function’s arguments object.

37
Q

What does the substring method do? And how do you use it?

A

Allows you to pull out letters from a string. For example: for var x = “Hello” I could do x.substring(0,4). This will give me “Ho”.

38
Q

Write a function which will return the sum when this statement is executed: console.log(sum(3)(4));

A

function sum (first) { return function (second) { return (first + second); } }

39
Q

What is the syntax to create an array?

A

var x = new Array(7)…. in parentheses, specify the number of items it will hold

40
Q

What is the syntax to create an array?

A

var x = new Array(7)…. in parentheses specify the number of items it will hold, or the items themself. the easier way which im used to is just create the square brackets and fill them with the items.

41
Q

What does JSON stand for?

A

JavaScript Object Notation

42
Q

What does “lexicographically” mean?

A

Alphabetically. (like when you want to sort an array lexicographically, it is alphabetically)

43
Q

Function vs method?

A

Both are functions; a method is just a function that is a property of an object.

44
Q

Why is it important to specify button type attribute and what are the different values? What are the two different ways to create a button?

A

A button with no attribute type acts as type=”submit” by default and will try to submit form when clicked. It also helps other developers to know its purpose. You can choose from submit, button, or reset… button or input type = “button”

45
Q

What does a non-numeric string convert to when doing a comparison to a number?

A

NaN

46
Q

What is the result of “2” > “12” ? And why?

A

True. Because when comparing numbers as strings, “1” is less than “2” alphabetically.

47
Q

What is the syntax to find out if we have a certain property in an object or not?

A

“in”… for example: “shape” in object1 - will return true if that property exists in object1

48
Q

What are the two ways to create arrays?

A

var x = []; or var x = new Array();

49
Q

What are the different types of loops? And when are they best used?

A

A for loop (default for iterations), while loop (good when you already have var defined somewhere outside), for each loop (for arrays… it can log the element, and then also the index number), for in (it will log the index number for arrays, and key for objects), and for of (use this if you don’t care about index or key.. it will give you the value).

50
Q

What is an enumerable property?

A

An enumerable property is one that can be included in and visited during for..in loops (or a similar iteration of properties, like Object.keys()).

51
Q

What are the different types of conditionals?

A

If else statements. Switch statements.

52
Q

What does “this” mean or refer to?

A

It refers to the current object we’re in

53
Q

What is the typeof some identifier that hasn’t even been declared as a variable yet?

A

undefined (still)