Chapter 2

Javascript Let Notes

Let gives variables a scope inside a block, this means they can be used only inside a block and cannot be redeclared inside that space. But it can be redeclared outside that space with any value. Same variable in same program without problems. You must declare a let variable before accessing. Var will always have global scope, which makes it sometimes more useful than let.

Chapter 2 Notes

Javascript is executed after the page loads. Javasxript can create variables, loops, make decisions based on data, and more variables can hold booleans, strings, integers, floating points to create a variable you need to declare it(using var or let and a name for the variable), and then set its value. Use a semi colon to end a line You can modify the value by changing it or adding to the current valuse(scoops = scoops +10;) You need to be particular about variable naming. Don't start them with numbers or symbols that aren't allowed. Use a letter, an underscore, or a dollar strings. After the first character, you can use whatever characters you wish. Be careful not to use any of Javascript's reserved words. These words cannot be used as varaible names. A list of reserved woirds can be found below these notes. You can do math, compare numbers, concatenate strings, create arrays, create functions, create elements id. Javascript will automatically convert between types. For example when multiplyin an integer by a float, or concatenating a number and a string. you can make while loops with conditions or for loops with conditions(same as C++ loops) If and if else statements can be used to apply logic to a program. Decides between options based on data. an else statement will catch anything that doesn't meet the conditions of if and if else statements. You can use an external script or write the code inside a script element. To link a script use the src attribute on a script element and then close the element. Javascript changes DOM and then website updates dynamically. document.getElementById("greenplanet"); get an element by id. After that you can modify the element with Javascript. The .innerhtml will allow you to modify the ciontents of the element. Don't touch the DOM until the page has loaded. If you put your actions into a function, you can use windows.onload to start running the function after the page loads. You can create, remove and, get elements, and set attributes from Javascript. You can create an array using new Array() and index that array using [] You can also write a name and add values like this: name[23,47, 66] To add another item to an array give an index and set it equal. name[3] = 22; You can reference an array and get the value in an expre3ssion. name[3] + name [4]

Reserved Words

abstract as boolean break byte case catch char class continue const debugger default delete do double else enum export extends false final finally float for function goto if implements import in instanceof int interface is long namespace native new null package private protected public return short static super switch synchronized this throw

Javascript Code Examples

Found in console after pressing inspect