Lightweight, cross-platform, single-threaded, and interpreted programming language for creating dynamic and interactive web content
JavaScript
JavaScript:
How does it function on the client side?
It runs on the user’s browser alongside HTML and CSS to enable user interaction
JavaScript: how does it function on the server side?
It functions by managing databases, file systems, and security
JavaScript: It enables a wide array of applications beyond the web. What are those?
Mobile app development
Game development
IoT
Real-time systems
It was sometimes dismissed as a “toy language” with limited capabilities
JavaScript
What you can build with JavaScript (examples)
What browsers have that let it execute JavaScript code
JavaScript Engine
Examples of JavaScript engines
SpiderMonkey (firefox)
v8 (chrome)
A C++ program that has chrome’s JavaScript engine (v8) embedded in it. It lets you run JavaScript outside a browser; lets you build the backend for web and mobile applications
Node
The standard for JavaScript
ECMAScript
Official name of JavaScript
ECMAScript
JavaScript lives between __ tags
script
(
and)
Old example of a tag containing JavaScript (inline)
<script type=”text/javascript”>
Where are scripts usually placed?
<head> and/or <body>
</body></head>
When scripts are put here, it runs before the page content loads. It might slow the rest of the page down
Scripts put in <head>
When script is put here, it runs as the page loads. It makes things snappier for users
Script in the <body>
Form of JavaScript that makes the code reusable and faster thanks to browser caching
External JavaScript
How do you reference external scripts
There should be no script tags in JavaScript files
Ok
JavaScript’s ways of displaying data
A way JavaScript displays data wherein it finds an existing element by its ID and updates the content
innerHTML()
Syntax of innerHTML() when used with a button and getting element id.
In other words. What would be the syntax if u were to use a button to replace a paragraph?
<button></button>
[Button name]
</button>
This code says:
“When someone clicks this button, go find the HTML element whose id equals whatever is inside those brackets ([id]) and replace its inner HTML (that’s the content inside the element) with whatever’s in [new replacement].”
Remember. The innerHTML part is necessary so it actually replaces the contents of the id’d element. If we remove that, nothing will happen.
A way of displaying data in Javascript that outputs it directly into the HTML document
document.write()
What do you put in the parenthesis in document.write()?
The output you want to display in the document
Example:
…
<p> I love JS </p>
<script>
document.write('hello world')
</script>Output:
I love JS
hello world
(note how it didn’t wipe out the entire html screen)