Skip to content

Instantly share code, notes, and snippets.

@dirkdunn
Last active March 6, 2017 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dirkdunn/312a9656d27a57ca14aa52bf279e4b2b to your computer and use it in GitHub Desktop.
Save dirkdunn/312a9656d27a57ca14aa52bf279e4b2b to your computer and use it in GitHub Desktop.

Javascript Fundamentals

  • Explain what a programming language is
  • Explain what JavaScript is and how it fits into web development
  • Explain what variables are and why they are useful in a program.
  • Explain the difference between expressions and statements
  • Use common operators with variables and literals for arithmetic, string concatenation, and assigning values to variables
  • Create a variable and assign a value to it
  • Explain what arrays are and why they’re needed
  • List some useful array helper methods
  • Explain what loops are and why they are useful in a program
  • Use the for, while, and forEach loop in javascript
  • Explain the different use cases for for, while, and forEach
  • Use console.log() to debug information

I DO

Set up HTML file, include javascript

What is a programming language, and how do they work? (5 min)
A special language programmers use to develop programs on the computer. It provides instructions to the computer to execute. It contains

What is JavaScript? What role does it play in web development (5 min)
Javascript is the programming language of the web. It's what defines the behavior and handles the interactions of our web apps. It is an event-driven language, meaning that based on the events that occurs between the user and the web page, javascript will do something.

What are primitive data types? (5 min)
Primitive data types are the types of data that come built into the programming language, these include. (Go over each primitive data types).

  • Boolean
  • Null
  • Undefined
  • Number (Integers & Floats)
  • String

WE DO

Variables (15 min)
Variables are simply a name for something in our code. We use them to make our code read more like english, and to avoid typing the same thing multiple times.

/*
Multi line
comment
*/

// Single line comment , you can't read me
var helloWorld = "Hello, World!";
var ten = 10;
var sixPlusFive = 6 + 5;
var sixGtFive = 6 > 5;
var n = null;
var und = undefined;

console.log(helloWorld);
console.log(ten);
console.log(sixPlusFive);
console.log(sixGTFive);
console.log(n);
console.log(und);

You can use operators to do things with variables. (25 min)

console.log("hi" === "hi");
console.log(1 === 1);
console.log(1 !== 1);
console.log(1 === 2);
console.log(5 < 7);
console.log(7 <= 7);
console.log(9 >= 9);
console.log("This is string " + "concatenation");
console.log("adding " + "multiple " + "string " + "together");
console.log(5 - 4);
console.log(6 / 3)
console.log(6 / 4);

// Modulus
console.log(6 % 2);
console.log(6 % 2 === 0);
console.log(6 % 4);
console.log(6 % 4 === 1);

// The OR operator
console.log( 5+5 === 10 || 5+5 === 9);

// The AND operator
console.log( 5+5 === 10 && 5+5 === 9);

> Explain Camel Case

Let's learn logic

Activity
Let's practice basic logic (15 minutes)

TRUE AND TRUE === ?
TRUE AND FALSE
FALSE AND FALSE
TRUE OR TRUE
TRUE OR FALSE
FALSE OR TRUE
FALSE OR FALSE

Break (10 min)

Arrays & Array Methods (30 minutes)

An array is a data type that can hold multiple pieces of information.

var arr = [1,2,3,4,5];
var names = ["Joey","James","Peter"];

// accessing information from arrays
console.log("My name is " + names[1]);

Array Methods

  • push
  • pop
  • concat
  • shift
  • unshift
  • concat
  • slice
  • splice

Write JS methods with arrays

Expressions VS statements (10 min)

Expressions produce a value, it is evaluated into something else.

// Expressions
5 * 3
6 % 2 == 0
// etc..

Statements perform an action, it is essentially a set of instructions to carry something out.

var statement = 'I have performed the action of creating a variable';
var arr = ["I", "have created", "an array", 5, 'Hoorah!'];

Break (10 min)

Loops

We use loops when we want to repeat things multiple times. It would be redundant for us to type the same code over and over again.

We have three kinds of loops, FOR loops, WHILE loops, and FOREACH loop.

For Loop

for(var i=0;i< 10; i++){
  console.log(i);
}

While Loop

var count = 0;

while(count < 10){
}

When to use for vs while? At the most fundamental level, we use a for loop when we know when we want to stop. We use a while loop when we don't know when we want to stop.

What is DRY?

YOU DO (Filler Final)

Let's group in teams create a calculator page with multiple functions that do different things that can be called. We created an adder function earlier, let's make other functions that do calculations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment