by Lindsey Dragun
lmdragun@gmail.com
Javascript was invented in 1995 and released in 1996
It was named after the popular "Java" language, even though it wasn't related to it
The ancestor of what we use today was eventually named "ECMAscript", and the current widely used forms are ES5 and ES6
There was almost a decade between ES5 and ES6, but newer versions will come out more quickly
console.log("Hello world");
console.log(5*5)
console.log(10/5)
console.log("This is a string")
console.log(2+2 === 4)
var array = ["red", "green", "blue"]
console.log(array[1])
var instructor = {
name: "Lindsey",
work: "Developer",
age: 32,
hasLived: ["Washington, DC", "Orlando, FL", "Rome, Italy", "Pittsburgh, PA"]
}
console.log(instructor.hasLived)
2 == 2 // true
2 == "2" // true
2 === "2" // false
2 === 2 //true
What's an unwanted surprise?
Since == doesn't care about type, you may end up with unexpected side effects
2 + 2 // 4
2 + "2" // "22"
function addTheseNumbers(num1, num2) {
return num1 + num2;
}
console.log(addTheseNumbers(4, 2)
var global = "anything can use this";
function parentFunction() {
var parentType = "only things within parentFunction's curly braces can access this";
function childFunction() {
var childType = "only things within childFunction's curly braces can access this";
}
}
function parentFunction() {
function childFunction() {
var childType = "we'll be returning this";
return childType;
}
return childFunction();
}
var callingParentFunction = parentFunction();
console.log(callingParentFunction);
Play around with this code and the return statement
var numbers = [1, 2, 5]
for(var x = 0; x < numbers.length; x++) {
console.log(array[x])
}
Here, it console logs each number as it loops through the numbers array.
X = 0, 0 is less than the length of the array, console.log the value at index 0 in the array, then add 1 to X
X = 1, 1 is less than the length of the array, console.log the value at index 1 in the array, then add 1 to X
.....
X = 3, X is a higher number than the length of the array, so stop
var numbers = [1, 2, 5]
for(var x = 0; x < numbers.length; x++) {
console.log(array[x])
}
var x = 0;
var y = 2;
if (x < y) {
console.log("true");
} else if (x === y) {
console.log("equals");
} else {
console.log("false");
}
<html>
<body>
<h1>
</h1>
<script src="helloworld.js"></script>
</body>
</html>
helloworld.html
var headingText = document.querySelector('h1');
headingText.textContent = 'Hello world!';
helloworld.js