2026-08-15 20:11
Status:
Tags: IBM IBM Full Stack Software Developer Professional Certificate Web Development Software Engineering JavaScript Programming Lanuages APIs HTML Websites Front End Back End Full Stack
IBM IHCJ - Module 3 - JavaScript Programming for Web Applications
==JavaScript Fundamentals
-
Introduction to JavaScript and ES6:
-
JavaScript- versatile and widely used programming language that is used in web development. It allows for devs to create interactive and dynamic websites which gives the user a much better experience
-
It was created in the mid 90 s, and is a programming language that is ran inside of a web browser basically.
-
It can do many things in regards to manipulating the DOM such as changing content, structure, and style
-
It is also basically what handles nearly ALL events on the page, which things like button clicks and mouse interactions, unless fundamental CSS animations or HTML functionality, are all done in javascript
-
When you visit a website, your browser downloads the HTML and CSS files of the site, along side the JS code, and then it would render the site and proceed to run the code given the entire system of the website
-
ECMAScript 6 (ES6):
- It was a significant upgrade to the overall language
- It introduced a lot of new things like syntax enchantments, new features, and improved functionality
- It was basically just a major milestone iteration for the JS language
-
Below is a diagram of some of the effects and uses of javascript in the case of web development:
-
-
Methods on how to create JavaScript Code:
- You can have inline JS which is basically where you use the
<script>HTML tag which allows you to then write JS code and syntax inside, making it generally messy in all honesty - You can have an External JavaScript File where you write all of the Javascript in a separate file that is then connected to your HTML document inside of the script tag once again via a reference attribute, this is generally the preferred and better method
- You can have inline JS which is basically where you use the
-
How to see outputs in JavaScript
-
In order to output data in JS you can use things like
console.log()which prints out data to the console in your browser -
You can also alter the DOM which is basically having javascript create or update an element inside of the document tree for HTML as a means of debugging, letting you see things like updating text, colors and other such items
-
-
Data Types and Variables:
-
Variables things that are written inside of your code that are used to store and manage data in the life cycle of your program. They can be thought of as containers that hold information
-
You can declare a variable as follows
var/let/const varName;which is a variable with one of the three attributes, -
a const means that variable cannot have a changed value,
-
var has function level scope and can be called anywhere in the function it was declared (so useful for nested if blocks, and
-
let was introduced inside of ES 6 and only has block level scoping
-
A variable reserves a spot in the programs memory, can can be declared with or without a value
-
Data Types are classifications or categories of the kinds of data that can be stored and manipulated inside of your program
-
JavaScript is an interpreted language, and therefore does not have as strict typing, and so it makes it much easier to now worry about types
-
Generally a type would be things like doubles, floats, int, strings, and bools, and all have different functionality and properties (these are called primitive data types)
-
There are also then data types that would hold multiple different types of values, so things like hash tables, arrays, lists, and even objects and functions I assume (these are called composite types)
-
-
Introduction to Functions and Types of Functions:
-
Functions- are a reusable block of code, that once defined, is able to be reused and executed multiple times at different points in the program
-
They are generally used for quality of life and organization of code within of a code base, allowing for FAR less work whenever trying to write a program
-
Function declaration is defined and detailed in the diagram below:
-
-
Categories of Functions-
- Non-parameterized functions- these are functions that do not require parameters to operate and can do their task without any given input. This means that (unless things they reference change) they will always give you the same output
- Parameterized functions- These are functions that take in one or more arguments that would be used inside of the function to modify or do something. You define them in the function declaration, and then input them whenever you wish to call the function
- The main difference between an argument and a parameter is that a param is defined with the function and is what you are able to pass in, while the argument is the actual thing that gets passed in
-
Different Ways of Writing Functions
- Function Declaration- the old school way of writing a function, where you basically, generally you declare it with a
functionkeyword and then a name, the params, and then the body of the code - Function Expression- these are a bit newer, and basically allow you to define a function inside of a variable and store a given returned value inside of that variable
-
-------------------------Types of Functions-------------------------
-
-
Named Functions- these are functions that have specific names and are able to be called by said name, they are generally declared pretty old school using the
functionkeyword and can be defined anywhere in your code -
These are good for debugging because their name is said in the JS call stack
-
-
Immediately Invoked Function Expression- is a function that is defined and executed IMMEDIATELY after it’s creation, generally would be used to contain and encapsulate variables within of private scope codes
-
This would help to prevent global scope contamination and variable conflicts
-
-
Arrow Function- basically a more concise way to write functions which was introduced inside of ES 6, and is generally used for short and simple functions
-
-
Anonymous Functions are functions that do not have a name which are generally used as arguments for other functions and assigned to variables
-
Generally these can be created using the arrow function syntax
-
-
JavaScript: Functions and Prototypes:
-
-
Function a block of code that can be called from any point in a script after being declared, it has things like function keyword, the name of the function, parenthesis with optional params, and then the body of the code
-
A function’s data types are determined by the values of the arguments that are being passed to the functin
-
If no specific return type is declared, the the function returns whatever type is required of it by the logic
-
-
In some weird way, a function can also be a class because it is something that is able to be put inside of a variable, this would mean that it can have state, and so it gets the
thiskeyword as well. This generally does not mean it has things like methods declared inside of it (it very well might be able to, fuck you javascript) -
-
Prototypes define properties and methods for all instances of the object
-
This exists for all JavaScript objects that can be constructured with the
newkeyword -
Generally, if you would like to add a new property or method to the object (for functions), it would require modifying the actual code of that given object, it can NOT be done just by calling the object itself
-
However this is possible with prototypes, as all objects have a prototype property, so you can toss in stuff that way
-
-
Any object that gets instantiated inherits the current state of the prototype (they are shared)
-
Which means that changes to a given prototype causes all objects using it to automatically inherit the new properties and functions within that prototype
-
This can be done also with scripts which can override prototype properties and functions
-
-
So basically if you look at it sort of, the actual self-executing function kind of has the function declaration inside of what would generally maybe be the function name and then the params right after, which if it takes in params I am sure can mess up clean syntax even more.
-
Generally though this allows a function to run separately (variable access wise) from the rest of the program
-
-
Introduction to Arrays:
-
Array- is a data structure that is used to store and organize a wide range of values such as primitive or composite data types
-
The ranges of data are stored in a sequence and each of the elements of data is accessible in an index or position
-
An array starts at zero so the first element is at zero and the second at one and what not
-
To declare an array in JS, you generally would use the const keyword because arrays are of fixed sizes (use lists for dynamic) but are declared as
const MyArray = [1, 2, 3]; -
You can index an array with
MyArray[0]to get the value one for example as a way of indexing -
To find out the length of an array use the
myArray.length -
Also I fucking lied, for some God-Forsaken reason arrays are mutable in javascript and so they are really lists, you can change, add, or remove elements inside of an array by indexing them and what not in JS
-
See Common JavaScript Elements in order to see the table of different array instances and different array manipulation methods
-
You can also have nested arrays which are also called multidimensional arrays and are generally used to represent more complex data structures like grids or something else like that (know sometimes as 2 D lists as well for that very reason)
-
-
Array Methods:
-
Arrays Methods are basically build in functions that are used on top of arrays that simplify out common array operations you might want to perform, making them much easier to use
-
Examples
- Iteration, filtering, transforming, search, aggregate (summarize or group), and more
-
Types of array Methods
forEach, Map, Filter, Reduce, Find
-
-
forEachmethod iterates through the array and is able to apply some form of code to that given element, this can be very useful for logical implementations, like say you have a bunch of DOM elements of a certain type, for each tab, make the tab blue whenever someone selects something for example -
the for each is a FUNCTION not a loop on it’s own, its basically a built in function that takes in a function as a parameter and hence why you declare a function with teh array syntax
-
-
Mapmethod which creates a new array by applying the provided function in the argument to each given element, and is generally used for modifying data without affecting original array -
The above hand code declares an array of objects each with it’s own given name and price properties
-
The map method then iterates through the product array, and then executes the product function for each element, saving the element inside of the product variable which generally means YOU DO NOT HAVE ACCESS TO THE ORIGINAL DATA
-
-
Filter Method- creates a new array based on if given elements in the original array pass specific conditions that you set forth, and is useful for basically well
filtering -
-
Reduce- is a method that allows you to reduce an array to a single given value by applying a function to each element. It is very useful for the organization of and aggregating of data
-
So basically, you can do something to the WHOLE of the data in order to REDUCE IT INTO A SINGLE PRODUCT
-
-
Find method is as it sounds, it generally is used to find the first element in an array that would satisfy a specific condition, good for searching for specific data
-
==Interactive Web Development with JavaScript and the DOM
-
JavaScript APIs:
-
Common APIs- Common APIs are used in JavaScript applications include:
-
-
To retrieve a node reference from the HTML DOM using Javascript, you would use the
document.getElementByIDwith the ID argument, and this helps you get one specific HTML or XML argument that you are then able to modify -
The
document.getElementsByTagName(name)node reference retrieves aNodeListof elements with that specific tag name, so this can be all buttons or all images or something like that, you can use thetagNameparameter as the literal name of HTML tag -
The
document.createElement()creates new nodes inside of the current document you are in. This lets you create new HTML elements on the fly and modify your HTML code as you go. You can then use functions to place the element in the appropriate location, likeinsertBefore, AppendChild, or replaceChild functions -
parentNode.appendChild(Node)is basically as it sounds, you append a new inter-node inside of the DOM tree and you can then basically use this for abstracting out where you would want things to go and what-not -
element.innerHTML(used after getting an element inside of a variable) retrieves or sets the contents within an HTML element, allowing you to edit whatever contents that element might have -
It returns all child elements as a text string, so you can modify said string to get a new element
-
element.stylethis is used in tandem with the above hand method, where you are cable to retrieve or change the CSS style of a given element, being returned and modified with a string text that you can then hand code yourself if you would like -
You can modify specific things with
element.style.color = "blue", not just entire styles -
Examples of modifying given attributes for elements of the DOM tree are given out in the table below:
-
-
Window Object Methods and events:
window.open(url, name, [features, replace])which returns a reference to a new window object for the web browser, allowing you to close the window later with a given close function, params in image abovewindow.onloadfunction can be used to start a function after the page is loaded, in case you basically have some start up book keeping you need to do or something- Further events are displayed above in image
-
-
JavaScript APIs (The Reading):
-
Most JavaScript APIs follow the Representational State Transfer (REST) architectural style. These are referred to as RESTful APIs, and follow the CRUD paradigm. CRUD stands for Create, Read, Update, and Delete, and model the four basic functionalities needed when communicating between services and with a database. In a REST environment, these CRUD operations are often aliased as follows:
- Create → POST
- Read → GET
- Update → PUT
- Delete → DELETE
-
-
Document Object Model (DOM) API
- The Document Object Model (DOM) API is one of the most basic JavaScript APIs available. It connects web pages to scripts by representing the structure of a document (e.g. an HTML web page) in memory, making it accessible for modification as required.
-
Client-Side JavaScript: with HTML:
- Scripts in HTML- a client-side script is a program that accompanies an HTML document or may be embedded directly into it (basically the JS Code)
- The script runs whenever the document loads, a link is activated, or a button is clicked, and this is generally all done on the client side because they are the ones loading the code in
- Although, there are other ways to run scripts inside of HTML that are used to give someone the ability to express how they want items to be rendered, that being things like running after an HTML document loads, validate forms and process input as it is being typed, dynamically create DOM elements, or execute after an event on the page is triggered
- The above hand is how you can include scripts inside of HTML code
- Some users might disable javascript from running inside of their general browser preferences. So you can use the
<noscript>tag in order to handle these kinds of situations - A
<noscript>tag basically lets someone access something they would like using an alternative method that would not require them to use JavaScript code, although it is noted, to use a<noscript>tag, it needs to be nested inside of a<script>tag, so think of it as the thing with image text for blind people - This is basically a way to have scripts occur during specific events or actions that the use might take like a mouse being over an element or on a button click
-
Client-Side JavaScript: with DOM:
- The Document Object Model (DOM)- is the programming interface between Xml / HTML and Javascript
- it is basically a browser-based interface for applications and scripts that loads the HTML code into memory as a given structure that can then be indexed by Javascript so that way it can can and modify things inside of it
- Think of it as an intermediary representation for HTML that can be changed with javascript
- Below are the FOUR different levels of DOM and each of their given additions and modifications
- Each browser has various levels of compatibility with the DOM standard, and the focus inside of these Notes and the whole of IBM-Introduction to HTML, CSS, and Javascript generally focuses on Level 1 Core and DOM Level 1 HTML APIs to access HTML elements
- Above is a graph representation of the DOM model for browsers
- The window is the head of the DOM and controls the environment that contains the document
- The History Object keeps internal details about recent pages inside of the browser, and is basically what lets you simulate things like the back and forward buttons
- The Location Object contains information about the URL of a page you are on
- The Navigator is a client side representation internet browser or user agent, and is generally NOT CONSISTENT ACROSS Browsers
- The Screen Object is used for determining the screen size of the browser, good for things like mobile devices
- The Document Object is the HTML documents loaded into a window, so basically the thing that provides access to all HTML things in the page
- The window is the main hierarchy for the entire tree, and all other things are born into it, and it would be the thing that you would use to run queries or some shit like that
- Generally, there are also important messages that might pop up using the window in case you need something or something goes wrong
- A given HTML Document portion of the model then also has it’s own given tree like structure that nests all of the documents occurring inside of your HTML Code, with an example image below:
- There are either things like element nodes which is everything under the document that is generally does not hold text, which would be all of the things that hold other things, even if they hold text themselves
- However, there are then also text nodes which are the things that would store actual text values associated with the element nodes and whatever else it is that you need them to be, they exist between the two given end tags of an element
-
JavaScript DOM Objects:
-
DOM HTML-related node types, these are DOM level 2 nodes that are applicable to HTML documents
-
-
Each node type is a numeric constant that is also then represented by an integer value
-
Therefore, an element node type is represented by the value of one, and holds other kinds of descriptions for different things
-
The different levels of each integer value represents the node that it is
-
The Node Name is the name of that given element or tag, so if you are looking at a
<div>element, then the node name is div -
However if it has something like
<div id="div123">This is a DIV</div>then the attribute name is “id” and the value is “dive 123” because you explicitly changed them -
This is also how I would assume CSS is able to tell what things are ID values or Class names and how to apply given styles to them
-
Below in the table are some DOM Level 2 Properties, which is basically the DOM Level 2 node object properties and the given type that they are
-
-
-
You can also access in child elements by just going down the list with the
.attribute, such as whenever you would rundocument.forms[0].elements[0]in order to get a specific attribute inside of the list that is made whenever the HTML document is loaded in
-
==Summary & Cheat Sheet
-
JavaScript is a scripting language that enables developers to add dynamic content to web pages.
-
JavaScript variables are declared using the ‘var’, ‘let’, or ‘const’ keywords and take their type from the value assigned.
-
JavaScript arrays are data structures used to store and organize collections of values.
-
Arrays can contain various data types, such as numbers, strings, objects, or other arrays.
-
JavaScript uses blocks of code, called functions, that can be called from anywhere in the script.
-
New methods and properties can be added to an object by modifying the prototype for that object.
-
Prototypes allow you to define properties and methods for all instances of a specific object.
-
Client-side scripts are programs that accompany HTML documents and are used by developers to incorporate more interactive elements.
-
The script tag can incorporate a script within an HTML document or call a script from an external file.
-
The Document Object Model (DOM) is the programming interface between HTML or XHTML and JavaScript.
-
Developers can access HTML DOM elements from JavaScript scripts using the correct DOM notation.
-
APIs are often used to access HTML DOM elements in web pages.
-
See Common JavaScript Elements for the cheat sheet
==Glossary
| Term | Definition |
|---|---|
| AJAX | “Asynchronous JavaScript and XML” that encompasses more than asynchronous server calls through JavaScript and XML. It is not programming language or technology but rather a programming concept. Ajax represents a series of techniques that provide richer, interactive web applications through HTML, JavaScript, Cascading style sheets, and modifying the web page through the Document Object Model. The name is misleading though because nowadays, JSON is commonly used instead of XML. |
| Anonymous Functions | A type of function that has no name or we can say which is without any name. It is declared without any identifier and is often used as a parameter of another function. It is a common way to execute a function immediately after its declaration. |
| Array | A data structure that aids the programmer in the storage and retrieval of data by indexed keys. Arrays use a zero-based indexing scheme, meaning that the first element of an array has an index of zero. Arrays grow or shrink dynamically by adding or removing elements. |
| Classes | Classes act as a blueprint or template for building objects with similar characteristics and behaviours. A class encapsulates data (in the form of properties) and functions (in the form of methods) that work on that data. |
| Client-Side Script | A program that accompanies an HTML doc or embedded in HTML. Scripts run during load of a document or when an action is performed.They can be used to validate forms, process input, or dynamically create document elements.Embed a script in HTML, with the • Use |
| Document Objects | Document representing the main web page that gives access to all HTML elements on the page. When page is loaded HTML doc becomes a document. It is referred to with “document”. |
| DOM | “Document Object Model” is a programming interface (API) between HTML and JavaScript. It allows for dynamically accessing and updating content, structure, and style. JavaScript uses the DOM to access and modify web page elements in the browser. |
| Element Nodes | All HTML tags. |
| Element Objects | The most general base class that all element objects in a Document inherit. It only has methods and properties common to all elements. Everything in a HTML page is an element. And one element can have other elements nested within itself. |
| Event | An event is something either a browser or a user does that the JavaScript can react to such as a button click or when a user submits input on a form. |
| Event Binding | Refers to telling the browser that a function should be called whenever some ‘event’ occurs. |
| Event Handlers | A function that declares what to do when an action is performed such as the click of a button. Example: Note that showAnswers() is an event handler. |
| Extend | This keyword is used in class declarations or class expressions to create a class that is a child of another class. |
| Functions | Functions are modules of code that execute a particular task. They may take-in data, called arguments or parameters, and sometimes return data as well, called the return value. Functions are commonly defined with this syntax: function functionName() { // function code; // optional return statement; } |
| IIFE | “Immediately Invoked Function Expression” runs immediately after it is defined. After the function executes it cannot be called again elsewhere in the program. It is a type of self-executing function. |
| Nodes | The basis of all elements in the Document Object Model (DOM) structure. |
| Objects | Objects are instances created from a class. They are real-world entities that represent the characteristics defined by the class. Objects have a special set of properties that store data and methods that specify behaviours. These methods and properties can be accessed and changed to carry out specific tasks and communicate with other programs. |
| Prototypes | A function prototype lets you easily define and add properties or methods to an object. Prototypes exist for all objects that can be created with the keyword”new”. All object constructors create objects that inherit properties and methods that are defined by the prototype. At instantiation objects inherit the current state of the prototype. Note however, that scripts can override prototype properties and functions. Following is an example of using a prototype to add a method to the Car class: function Car(make, model, year) { this.make = make; this.model = model; this.year = year; } Car.prototype.getName = function() { return this.make + ‘ ’ + this.model + ‘ ’ + this.year; } |
| Script | Offers developers means to modify and extend HTML documents in highly interactive ways. Scripts can be used to validate forms or to process input as it is typed. Scripts can be triggered by events that occur on a web page, such as the clicking of a button. Scripts can be used to dynamically create document elements on an HTML page. |
| Self-Executing Functions | Often used to initialize data or declare DOM elements. These functions can be anonymous. |
| Text Nodes | The nodes that contain actual text that go between an element start tag and end tag. |
| this | Keyword “this” refers to current instance of the object. The value of “this” can vary depending on how the object is called. |
































