JavaScript and TypeScript course · Module 1: JavaScript Basics
History and Significance of JavaScript
In this lesson6
Welcome to the fascinating world of JavaScript! Just as paleontologists discover the secrets of the past in Jurassic Park, we will dive into the history and significance of the language that revolutionized how we perceive and create modern web applications.
The Birth of JavaScript
JavaScript was born in 1995, thanks to Brendan Eich, who created it in just 10 days while working at Netscape Communications. Initially named "Mocha," then "LiveScript," it ultimately adopted the name "JavaScript" for marketing reasons, to capitalize on the popularity of Java, even though the two languages have little in common beyond syntactic similarities.
It's a bit like discovering a new species of dinosaur - although it may resemble previously known creatures, it has its own unique features and abilities!
Evolution of the Language
JavaScript, much like the world of dinosaurs, has gone through many evolutionary "eras":
- 1997: Standardization as ECMAScript (ES1)
- 1999: ES3 introduced more advanced regular expression features, exception handling (try/catch), and better string support
- 2009: ES5 added array methods (map, filter, reduce), strict mode, and better JSON support
- 2015: ES6/ES2015 brought a true revolution with new data structures, classes, arrow functions, modules, promises, and many other features
- 2016-present: Annual updates (ES2016, ES2017...) adding new functionalities
This evolution resembles the adaptation of dinosaurs to a changing environment - JavaScript has continuously evolved to meet the demands of increasingly complex web applications.
The Significance of JavaScript in the Web Ecosystem
JavaScript is like the T-Rex of web programming - it stands at the top of the food chain! It is the only programming language natively supported by browsers, making it essential for creating interactive websites. Its significance can be summarized in a few key points:
1. Ubiquity
JavaScript can be found on virtually every modern website. According to statistics, it is used on over 95% of all websites.
2. Versatility
JavaScript has broken free from browser constraints and can now be found:
- On the server (Node.js)
- In mobile applications (React Native, Ionic)
- In desktop applications (Electron)
- In IoT (Internet of Things) and embedded devices
3. Rich Ecosystem
The JavaScript ecosystem is like a thriving environment, full of frameworks, libraries, and tools:
- Frontend frameworks (React, Angular, Vue)
- Backend frameworks (Express, Nest.js)
- Build tools (webpack, Parcel)
- Full-stack solutions (Next.js, Nuxt)
JavaScript and the Future
JavaScript, much like dinosaur genomes preserved in amber in Jurassic Park, contains possibilities that we have only begun to discover. With the growing popularity of WebAssembly, JavaScript can work alongside high-performance compiled code, opening new possibilities for web applications.
Just as the scientists in Jurassic Park used breakthrough technologies to bring extinct species back to life, developers are constantly developing new JavaScript-based technologies, pushing the boundaries of what is possible on the web.
Why Learn JavaScript?
Learning JavaScript is like obtaining the key to the gates of Jurassic Park - it opens access to a fascinating world of possibilities:
- Huge job market - JavaScript developers are among the most sought-after IT specialists
- Rapid prototyping - the ability to quickly create interactive applications
- Low barrier to entry - all you need to start learning is a web browser
- Versatility - one language, countless applications
Summary
JavaScript, much like the dinosaurs in Jurassic Park, has come a long way in evolution from humble beginnings to dominance in its ecosystem. Today it is a fundamental element of web development and continues to expand its territory.
In the following lessons, we will delve into the practical aspects of JavaScript, learning to "tame" this powerful language, just as the trainers in Jurassic Park learned to work with prehistoric creatures.
Get ready for a fascinating journey through the world of JavaScript - your pass to creating your own technological wonders, as astonishing as dinosaurs brought back to life!
Code for this lesson: index.js
// Welcome to the world of JavaScript!
// Learning the history and significance of the language
console.log("Welcome to the JavaScript Jurassic Park!");
// 1. JavaScript through different periods - language evolution
console.log("\n=== JavaScript Evolution ===");
// ES5 (2009) - basic array methods
const dinosaurNames = ["Tyrannosaurus", "Triceratops", "Velociraptor", "Stegosaurus"];
// map method - data transformation
const dinosaursWithTitle = dinosaurNames.map(function(name) {
return "Dr. " + name;
});
console.log("ES5 map:", dinosaursWithTitle);
// filter method - data filtering
const longNames = dinosaurNames.filter(function(name) {
return name.length > 10;
});
console.log("ES5 filter (long names):", longNames);
// 2. ES6/ES2015 - modern features
console.log("\n=== ES6+ Modern JavaScript ===");
// Arrow functions
const modernDinosaurs = dinosaurNames.map(name => `${name}`);
console.log("ES6 arrow functions:", modernDinosaurs);
// Template literals
const favoriteDinosaur = "Tyrannosaurus Rex";
const description = `My favorite dinosaur is ${favoriteDinosaur}.
It is the king of all dinosaurs!`;
console.log("Template literals:", description);
// Destructuring
const [first, second, ...rest] = dinosaurNames;
console.log("Destructuring - first:", first);
console.log("Destructuring - second:", second);
console.log("Destructuring - rest:", rest);
// 3. Dinosaur objects - different creation methods
console.log("\n=== Creating objects ===");
// ES5 way
function createDinosaurES5(name, period, diet) {
return {
name: name,
period: period,
diet: diet,
roar: function() {
return this.name + " says: ROAAR!";
}
};
}
const trex = createDinosaurES5("T-Rex", "Cretaceous", "Carnivore");
console.log("ES5 object:", trex);
console.log("ES5 method:", trex.roar());
// ES6+ way - shorthand object syntax
function createDinosaurES6(name, period, diet) {
return {
name,
period,
diet,
roar() {
return `${this.name} says: ROAAR!`;
},
getInfo() {
return `${this.name} lived in the ${this.period} period and was a ${this.diet}`;
}
};
}
const velociraptor = createDinosaurES6("Velociraptor", "Cretaceous", "Carnivore");
console.log("ES6 object:", velociraptor);
console.log("ES6 info:", velociraptor.getInfo());
// 4. ES6 Classes
console.log("\n=== ES6 Classes ===");
class Dinosaur {
constructor(name, period, diet, weight) {
this.name = name;
this.period = period;
this.diet = diet;
this.weight = weight;
}
roar() {
return `${this.name} lets out a mighty roar!`;
}
getDetails() {
return {
name: this.name,
period: this.period,
diet: this.diet,
weight: `${this.weight} kg`,
sound: this.roar()
};
}
// Static method
static compareDinosaurs(dino1, dino2) {
if (dino1.weight > dino2.weight) {
return `${dino1.name} is heavier than ${dino2.name}`;
} else if (dino1.weight < dino2.weight) {
return `${dino2.name} is heavier than ${dino1.name}`;
} else {
return `${dino1.name} i ${dino2.name} have similar weight`;
}
}
}
const stegosaurus = new Dinosaur("Stegosaurus", "Jurassic", "Herbivore", 5000);
const allosaurus = new Dinosaur("Allosaurus", "Jurassic", "Carnivore", 4000);
console.log("Stegosaurus:", stegosaurus.getDetails());
console.log("Comparison:", Dinosaur.compareDinosaurs(stegosaurus, allosaurus));
// 5. Promises and async/await - simulating data loading
console.log("\n=== Asynchronicity ===");
// Promise
function loadDinosaurData(name) {
return new Promise((resolve, reject) => {
setTimeout(() => {
const dinosaurDB = {
"Tyrannosaurus": { period: "Cretaceous", discovered: 1905 },
"Triceratops": { period: "Cretaceous", discovered: 1889 },
"Stegosaurus": { period: "Jurassic", discovered: 1877 }
};
if (dinosaurDB[name]) {
resolve({ name, ...dinosaurDB[name] });
} else {
reject(new Error(`Dinosaur ${name} was not found in the database!`));
}
}, 1000);
});
}
// Async/await
async function getDinosaurInfo(name) {
try {
console.log(`Searching for info about ${name}...`);
const data = await loadDinosaurData(name);
console.log(`Found: ${name} from the ${data.period}, discovered in ${data.discovered} year`);
return data;
} catch (error) {
console.log("Error:", error.message);
}
}
// Test different functions
getDinosaurInfo("Tyrannosaurus");
getDinosaurInfo("Brontosaurus"); // This one doesn't exist in the database
// 6. Modules - export and import (simulation)
console.log("\n=== Modules (simulation) ===");
// Simulating export/import
const DinosaurModule = {
// Exported functions
createHerbivore(name, weight) {
return new Dinosaur(name, "Unknown", "Herbivore", weight);
},
createCarnivore(name, weight) {
return new Dinosaur(name, "Unknown", "Carnivore", weight);
},
// Exported constant
PERIODS: ["Triassic", "Jurassic", "Cretaceous"],
// Default export
default: Dinosaur
};
// Using "imported" functions
const brachiosaurus = DinosaurModule.createHerbivore("Brachiosaurus", 80000);
const spinosaurus = DinosaurModule.createCarnivore("Spinosaurus", 7000);
console.log("Brachiosaurus:", brachiosaurus.getDetails());
console.log("Available periods:", DinosaurModule.PERIODS);
// 7. Demonstration of all data types
console.log("\n=== Data types in JavaScript ===");
const dataTypes = {
// Primitive types
string: "Tyrannosaurus Rex",
number: 68000000, // Age in years
boolean: true, // Whether it's a carnivore
undefined: undefined,
null: null,
symbol: Symbol("unique-dinosaur-id"),
bigint: 999999999999999999999n,
// Objects
object: { name: "Triceratops", horns: 3 },
array: ["T-Rex", "Velociraptor", "Triceratops"],
function: function() { return "I am a function!"; },
date: new Date(),
regexp: /dinosaur/gi
};
console.log("All data types:");
for (const [key, value] of Object.entries(dataTypes)) {
console.log(`${key}: ${typeof value} = ${String(value)}`);
}
console.log("\nCongratulations! You've learned the history and basics of JavaScript!");Spotted a mistake in this lesson?
Check yourself
Answer the questions from this lesson. Pick an answer to see right away whether it is correct.
1. What is JavaScript?
2. Who created JavaScript?
3. Which characteristic does NOT describe JavaScript?
4. What is the relationship between JavaScript and Java?
5. What is ECMAScript?
Hands-on tasks in the game
- Vertical ordering
Arrange the JavaScript milestones in chronological order: