Five facts about Javascript
JavaScript: the language that empowers web developers to breathe life into static web pages, making them dynamic and interactive.
If HTML is the skeleton of a website and CSS its stylish outfit, JavaScript is the charming personality. But like any charming personality, it's full of surprises, quirks, and idiosyncrasies.
In this article, we'll explore five interesting facts about JavaScript. And, who knows? By the end of this, JavaScript might just be your new favorite language (or your favorite thing to joke about at nerdy parties).
Java ≠ JavaScript
"Java is to JavaScript as car is to carpet," this has been a running joke in the developer community for years. Why, you ask?
Java and JavaScript are two entirely different programming languages, both in design and functionality. Yes, both of them got the "Java" bit, but that's pretty much where the similarity ends.
For example, here's how you write a simple "Hello, World!" program in both languages:
Java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
JavaScript
console.log("Hello, World!");
Clear as mud, right? The confusion is historical, with JavaScript being named to capitalize on Java's popularity in the mid-'90s. So, when someone confuses the two, just smile and share the carpet anecdote.
JavaScript is Multi-Paradigm
Ever met someone who's a rock star, painter, and an excellent chef, all rolled into one? That's JavaScript for you.
JavaScript is a multi-paradigm language that supports multiple programming styles, including procedural, object-oriented, and functional programming.
Here's a simple functional programming example:
const array1 = [1, 4, 9, 16];
const map1 = array1.map(x => x * 2);
console.log(map1);
// output: Array [2, 8, 18, 32]
JavaScript is a welcoming language ready to accommodate, no matter your preferred style. JavaScript - the ultimate people-pleaser in the coding world!
The Birth of JavaScript was a Whirlwind
Even if you're not a fan of JavaScript's quirks, you have to respect its hustle.
JavaScript was created in just 10 days by Brendan Eich in 1995. Yes, you heard it right. This MVP (Minimal Viable Product) approach gave us one of the world's most widely used programming languages. Talk about a quick delivery!
Undefined ≠ Null
In JavaScript, undefined and null might seem like two sides of the same coin, but they're more like distant cousins.
'undefined' means a variable has been declared but hasn't been assigned a value. 'null', on the other hand, is an assignment value that means no value or no object. It's like the difference between forgetting to buy milk (undefined) and deciding you don't need milk at all (null).
let testVar;
console.log(testVar); // undefined
testVar = null;
console.log(testVar); // null
Now, isn't that null-ifying?
JavaScript is Everywhere
Lastly, and perhaps most impressively:
JavaScript isn't just for web browsers. With the advent of Node.js, you can now write server-side code, develop desktop applications, build mobile apps, and even control robots with JavaScript. It's like the secret sauce that adds a little spice to every dish!
Here's a simple server setup with Node.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(3000, '127.0.0.1', () => {
console.log('Server running at http://127.0.0.1:3000/');
});
So, next time you're typing away at your JavaScript code, remember, you're not just coding, you're performing magic that could control anything from websites to robots!
And there you have it - five fascinating facts about JavaScript.
This language isn't just about coding; it's about humor, history, and a healthy dose of idiosyncrasy.
JavaScript can be a quirky friend, a strict teacher, or a flexible ally. Whether you love it, hate it, or love to hate it, you can't deny - JavaScript keeps the world of web development interesting.