Lesson 0 Flashcards
1
Q
What’s the code to print in the browser’s console?
A
console.log(“Hello world”);
2
Q
JavaScript variable syntax
A
- String \+ var firstName = "james"; \+ Always put var first. Strings are inside "". - Numbers \+ var age = 32;
3
Q
What is the replace method?
A
- The .replace() method returns a new string with some or all matches of a pattern replaced by a replacement. JavaScript
- Example:
var email = “udacity.com”;
var newEmail = email.replace(“udacity, “gmail”);
4
Q
What is the append method?
A
- The .append() method inserts the specified content as the last child of each element in the jQuery collection.
- Example:
//Original html
<h2>Greetings</h2><div>
<div>Hello</div>
<div>Goodbye</div>
</div>
//jQuery $( ".inner" ).append( "<p>Test</p>" );
//Result in the html
<h2>Greetings</h2> <div class="container"> <div class="inner"> Hello <p>Test</p> </div> <div class="inner"> Goodbye <p>Test</p> </div> </div>
- You can also select an element on the page and insert it into another: //jQuery $( ".container" ).append( $( "h2" ) );
5
Q
What is the prepend method?
A
- The prepend() method inserts specified content at the beginning of the selected elements.
6
Q
Function Syntaxis?
A
var udacityizer = function(s) {
s = s.replace("au","U"); return s; };
7
Q
6 Falsy values
A
- false
- 0
- ”” (empty string)
- null (Variable with no value)
- undefined (A nonexisting variable)
- NaN
8
Q
Array Syntaxis
A
- var myArray = [item1, item2];
- Example:
var skills = ['’pig”, ‘‘cow”];
9
Q
for Syntaxis
A
- for (index = 0; index
10
Q
object Syntaxis
A
- There are no classes in JS.
- Example:
var bio = {
“name” : “James”,
“age” : 32,
“skills” : skills
};
//Acess bio name bio.name
//Adding properties to obj 1 bio.city = "Bogota";
//Adding properties to obj 2 bio["city"] = "Bogota";
11
Q
What is JSON?
A
- JavaScript Object Notation. JSON is a popular and simple format for storing and transferring nested or hierarchal data.
- JSON allows for objects (or data of other types) to be easily encapsulated within other objects.
12
Q
How to lint my JSON?
A
- You should copy and paste your code into a JSON linter like jsonlint.com to quickly and easily find syntax errors. A linter is a piece of software that analyzes code for syntax errors.
13
Q
JSON object example
A
var education = { "schools": [ { "name": "university", "major": ["compu", "bio"] }, { "name": "university", "major": ["compu", "bio"] }, ] };
14
Q
What is the DOM?
A
- Is part of the process of building websites, browsers convert all of the HTML they receive into a JavaScript object called the Document Object Model (DOM).
15
Q
Bracket notation
A
- planet[“name”]
- Bracket notation always works. Dot notation requires properties that begin with a letter and do not include special characters.