0% found this document useful (0 votes)
56 views33 pages

PP 14

This document provides an overview of JavaScript Level Two course material. It covers functions, arrays, and objects. For functions, it explains syntax, parameters, and using functions. There are exercises to practice functions. Arrays allow storing and accessing data in sequences. Object exercises involve adding methods to objects. Objects store information as key-value pairs and can have methods.

Uploaded by

raji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views33 pages

PP 14

This document provides an overview of JavaScript Level Two course material. It covers functions, arrays, and objects. For functions, it explains syntax, parameters, and using functions. There are exercises to practice functions. Arrays allow storing and accessing data in sequences. Object exercises involve adding methods to objects. Objects store information as key-value pairs and can have methods.

Uploaded by

raji
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

JavaScript Level Two

JavaScript Level Two


Django Bootcamp

● Welcome to Javascript Level Two.


● So far we’ve only learned the basics of
Javascript, it is time to expand our
understanding by learning about more
advanced material!
Django Bootcamp

● In this section we will cover:


○ Functions
○ Arrays
○ Objects
● We will also have exercises for each of
these topics for plenty of practice!
Let’s get started!
JavaScript Level Two
Part 1 - Functions
JavaScript Level Two
Django Bootcamp

● Functions will be our main building


blocks.
● They will allow us to easily reuse code
more than once and not constantly
repeat ourselves.
Django Bootcamp

● The general syntax for a JS function is:


○ function name(parameter1, parameter2){
//Code to be executed
}
Django Bootcamp

● We use the function keyword to indicate


that we have a function.
○ function name(parameter1, parameter2){
//Code to be executed
}
Django Bootcamp

● Then we have the option of passing in


parameters (we could also not have any
parameters).
○ function name(parameter1, parameter2){
//Code to be executed
}
Django Bootcamp

● Someone using the function could pass


in parameters required for the function
to do something with.
○ function name(parameter1, parameter2){
//Code to be executed
}
Django Bootcamp

● Let’s go straight to the editor and our


console to really show how to create and
use functions in Javascript!
○ function name(parameter1, parameter2){
//Code to be executed
}
Part 2 - Function
Exercises
JavaScript Level Two
Django Bootcamp

● Let’s get some practice with functions,


open up the file:
○ Part2_Functions_Exercises.js
● The problems gradually get harder.
● Let’s take a quick look at the problems!
Part 2 - Function
Exercises - Solutions
JavaScript Level Two
Part 3 - Arrays
JavaScript Level Two
Django Bootcamp

● Arrays will allow us to store various basic


data types in a sequence, so we can then
later access them as needed.
● This is best explained through example
code, so let’s get started!
Part 4 - Array Exercise
JavaScript Level Two
Django Bootcamp

● It is time to practice using arrays in a


more realistic situation.
● We will create a student roster app using
the Javascript that we know so far.
● Let’s check out:
○ Part4_Array_Exercise.html
Part 4 - Array Exercise
Solution
JavaScript Level Two
Part 5 - Objects
JavaScript Level Two
Django Bootcamp

● JS Objects are hash-tables, they store


information in a key-value pair.
● In other languages this is sometimes
also called a dictionary.
● Unlike an array a JS Object does NOT
retain any ordering.
Django Bootcamp

● The name “Object” can sometimes be


confusing when coming from another
language because it sounds so generic,
so keep that in mind.
Django Bootcamp

● The typical JS Object is in the form:


● { key1 : “value one”, key2 : “value two”,...}
● You then access values through their
corresponding key
● Let’s see some examples of this and learn
more about JS Objects!
Part 5 - Objects
Continued
JavaScript Level Two
Django Bootcamp

● Let’s continue by discussing Object


methods.
● Object methods are essentially functions
that are inside of an Object.
Django Bootcamp

● var carInfo = {
make: "Toyota",
year: 1990 ,
model: "Camry" ,
carAlert: function(){
alert("We've got a car here!")
}
};
Django Bootcamp

● More realistically you will want to use key


value pairs from the object itself, in that
case you use the special this keyword.
● The this keyword can be confusing for
beginners at first, so don’t worry if you
don’t immediately fully grasp it.
Django Bootcamp

● The this keyword acts differently


depending on the situation.
● For a JS Object, the this is set to the
object the method is called on.
● For example...
Django Bootcamp

● var myObj = {
prop: 37,
reportProp: function() {
return this.prop;
}
};
console.log(myObj.reportProp()); // logs 37
Django Bootcamp

● Good Link for More Details:


● https://developer.mozilla.org/en-US/docs/Web/J
avaScript/Reference/Operators/this
● Let’s code out a few examples of Object
Methods!
Part 6 - Objects
Exercise
JavaScript Level Two
Django Bootcamp

● For this exercise check out the file:


○ Part6_Objects_Exercise.js
● It contains three objects along with tasks
that involve you adding methods to each
of the objects.
● Let’s get a quick look!
Part 6 - Objects
Exercise
Solutions
JavaScript Level Two

You might also like