Recently, I was asked a JavaScript question in an interview that honestly stumped me at first 😅 — it really tested my core JS understanding. 💡 Question: “Why does JavaScript allow you to add functions to the Math library, but Java does not?” At that moment, I couldn’t answer it. Later, when I looked it up, I found the explanation really interesting 👇 In JavaScript, Math is just a normal object — dynamic and extendable. You can add new methods like this: Math.square = function(x) { return x * x; }; console.log(Math.square(5)); // ✅ 25 But in Java, Math is a final class with static methods — you can’t inherit or modify it. This keeps the system stable and predictable, which aligns with Java’s strong type and compile-time safety philosophy. I found this question such a great reminder of how JavaScript’s flexibility and Java’s rigidity come from totally different design goals. #JavaScript #Java #InterviewQuestions #LearningEveryday #Developers #Programming
Why JavaScript allows adding functions to Math, but Java doesn't
More Relevant Posts
-
JavaScript taught me something cool today 🤔 You know how we write classes in JavaScript? Turns out, JS doesn't actually have "real" classes like Java or C++. It's a Prototype-based language wearing a class costume! ✨ ➡️When we write this: class Person { constructor(name) { this.name = name; } greet() { return `Hello, I'm ${this.name}`; } } ➡️ JavaScript actually does this: function Person(name) { this.name = name; } Person.prototype.greet = function() { return `Hello, I'm ${this.name}`; } 🔺 Same result, different reality! The class syntax is just syntactic sugar to make it look familiar. Under the hood, everything still runs on Prototypes, implementing Inheritance, Encapsulation, Abstraction and Polymorphism in its own unique way. 📌 Understanding this helped me: • Finally get why this acts weird sometimes • Debug inheritance issues way faster • Realize methods live on the prototype (memory efficient!) 🖊️ Anyone else had this "wait, what?" moment with JavaScript? 😅 #JavaScript #WebDevelopment #LearningToCode
To view or add a comment, sign in
-
💡 Did you know? In languages like Java or C++, changing a variable’s data type after it’s declared isn’t allowed. But in JavaScript, it’s totally possible — that’s what makes it so flexible and dynamic! ⚡ Example 👇 javascript let value = 10; // value is a number value = "Ten"; // now it's a string console.log(value); // Output: Ten This feature is called dynamic typing — one of JavaScript’s coolest traits! 👉 If you already knew this, drop a 💬 in the comments! #JavaScript #Programming #WebDevelopment #CodingFacts #LearnToCode #TechInsights
To view or add a comment, sign in
-
🚀 𝐔𝐧𝐝𝐞𝐫𝐬𝐭𝐚𝐧𝐝𝐢𝐧𝐠 𝐓𝐲𝐩𝐞𝐬 𝐨𝐟 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐢𝐧 𝐣𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭 🚀 In JavaScript, functions can be written in several ways, and each type has its own purpose. Function Declaration is the basic way to create a function using the function keyword. It can be called before it’s defined. ✨ 𝐍𝐚𝐦𝐞𝐝 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A regular function with a name, defined using the function keyword. It can be called multiple times and improves code readability. 🕒 𝐀𝐧𝐨𝐧𝐲𝐦𝐨𝐮𝐬 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A function without a name, often used inside other functions as callbacks like in setTimeout or addEventListener. ⚡ 𝐀𝐫𝐫𝐨𝐰 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A modern and shorter syntax that makes code cleaner and inherits this from its surrounding scope. 🚀 𝐈𝐈𝐅𝐄 (𝐈𝐦𝐦𝐞𝐝𝐢𝐚𝐭𝐞𝐥𝐲 𝐈𝐧𝐯𝐨𝐤𝐞𝐝 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 𝐄𝐱𝐩𝐫𝐞𝐬𝐬𝐢𝐨𝐧) — A function that runs immediately after it’s defined. It’s useful to keep variables private and avoid polluting the global scope. 🧠 𝐇𝐢𝐠𝐡𝐞𝐫-𝐎𝐫𝐝𝐞𝐫 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A function that takes another function as an argument or returns a function. This is often used in functional programming, like with map, filter, or forEach. 🏗️ 𝐂𝐨𝐧𝐬𝐭𝐫𝐮𝐜𝐭𝐨𝐫 𝐅𝐮𝐧𝐜𝐭𝐢𝐨𝐧 — A special type of function used with the new keyword to create and initialize objects. 🌟 Great insights from Codexign, worth sharing! #javascript #js #softwaredeveloper #JavaScriptTips #Functions #FunctionsInJavaScript #JSTutorial #webdevelopment #frontenddevelopment #CodingTips #JavaScriptDeveloper #JavaScriptTypes #Programming #Coding #JSLearning #JSTypes #education #LearnJavaScript #technology #w3schools #careers
To view or add a comment, sign in
-
Advanced Beginner’s guide to ClojureScript So how does your tiny ClojureScript program transform into runnable JavaScript? (ns app.core) (println "Howdy!") First of all, you need a compiler! ClojureScript is a hosted language, which means you have to compile it into JavaScript, unless you want to ship the compiler into a browser to be able to interpret ClojureScript at runtime, which is slow and in most cases doesn't make sense (but maybe you wanna build online REPL, that's ok). This is not going to be easy. ClojureScript sits on top of JavaScript, the compiler is a library written in Clojure, which in turn hosts on JVM. This means you need Java installed, huh. I prefer to use sdkman to manage my Java installations. sdk install java Next step is to install Clojure, head over to installation guide at clojure.org. If the following command returns 2, you are good! clj -M -e "(inc 1)" Create project directory somewhere and put deps.edn file into it with the following contents. deps.edn is kind of package.json, if you are coming https://lnkd.in/g9RtJYyC
To view or add a comment, sign in
-
Is JavaScript a Compiler or an Interpreter? It’s been a while since my last post, but I came across an interesting poll recently - it asked whether JavaScript is a compiler or an interpreter. Most people voted for interpreter, which makes sense… but it’s not completely true anymore. In the early days, JavaScript was interpreted, meaning it ran line by line without being compiled first. But that changed with modern engines like V8 (used in Chrome and Node.js). Today, JavaScript uses Just-in-Time (JIT) compilation, which means it starts by interpreting code, then compiles and optimizes the parts that run often - making it much faster over time. Here’s a quick breakdown of the main compilation types: Ahead-of-Time (AOT): Code is compiled before running (like C, C++, Rust). Just-in-Time (JIT): Code is compiled while running (like Java, C#, JavaScript). Interpreted: Code runs line by line without compilation (like Python, early JavaScript). So, is JavaScript interpreted or compiled? It’s actually both - it starts interpreted and becomes compiled as it runs. Pretty cool how much JavaScript has evolved, right? #javascript #compilation #aot #jit #interpreter #compiler
To view or add a comment, sign in
-
-
JavaScript Deep Dive: The Story Behind null Today, I explored the origins of one of JavaScript’s quirkiest features — null. It turns out this little value has a surprising history! 🔹 Where it Began: JavaScript was created in 1995 by Brendan Eich in just 10 days. Since it was inspired by Java, null was included to represent the intentional absence of any object — just like in Java. 🔹 The Famous Bug: Ever wondered why this happens? typeof null // "object" This result is actually due to an early implementation bug. null was given the same type tag as objects — and fixing it would have broken lots of existing code. So it stayed. 😅 🔹 null vs undefined: JavaScript defines two empty values: null: Intentionally empty (set by programmers) undefined: Automatically assigned by JavaScript for missing or uninitialized values This distinction has confused developers for decades! 🔹 Standardized in ECMAScript: Both null and undefined were formalized in the first ECMAScript standard (1997), cementing their roles in the language. 💡 Takeaway: JavaScript's null is a great example of how early design decisions — even mistakes — can shape a language's future. Knowing its history helps us write code with more clarity and intention. Let’s keep learning the story behind the code! 🎯 #JavaScript #LearningInPublic #WebDevelopment #HistoryOfJS #Programming #10000Coders #CodeNewbie
To view or add a comment, sign in
-
-
Well-Known Symbols and Their Applications Comprehensive Guide to Well-Known Symbols in JavaScript and Their Applications Introduction JavaScript, an essential language for web development, has an ecosystem that is rich in features and often compared to Java, C#, or Python for its dynamic capabilities. One of the lesser-known yet powerful features of the language is its "Well-Known Symbols." Introduced in ECMAScript 2015 (ES6), these symbols serve as unique keys for object properties and facilitate advanced programming concepts, including meta-programming. This article delves into the historical context, technical intricacies, practical applications, performance considerations, and advanced use-cases of Well-Known Symbols, ultimately providing a robust guide for experienced developers. The concept of symbols in JavaScript stems from the need for unique identifiers that do not clash with property names in objects. Prior to ES6, developers employed various workarounds like string concatenation or object literals, eac https://lnkd.in/gn2kiRnA
To view or add a comment, sign in
-
Well-Known Symbols and Their Applications Comprehensive Guide to Well-Known Symbols in JavaScript and Their Applications Introduction JavaScript, an essential language for web development, has an ecosystem that is rich in features and often compared to Java, C#, or Python for its dynamic capabilities. One of the lesser-known yet powerful features of the language is its "Well-Known Symbols." Introduced in ECMAScript 2015 (ES6), these symbols serve as unique keys for object properties and facilitate advanced programming concepts, including meta-programming. This article delves into the historical context, technical intricacies, practical applications, performance considerations, and advanced use-cases of Well-Known Symbols, ultimately providing a robust guide for experienced developers. The concept of symbols in JavaScript stems from the need for unique identifiers that do not clash with property names in objects. Prior to ES6, developers employed various workarounds like string concatenation or object literals, eac https://lnkd.in/gn2kiRnA
To view or add a comment, sign in
-
Stop me if you've heard this: "Learn JavaScript." "No wait, learn Python first." "Actually, start with Go." "Real devs use Rust." "Just use PHP, it pays the bills." Meanwhile, the dev who only knows HTML and CSS just made $15K/month building Webflow sites. You don't have a language problem. You have a "which language will actually make me money right now" problem. Pick one. Build something. Ship it. Figure out the rest later. Analysis paralysis killed more dev careers than bad code ever did. #WebDev #Programming #DevLife #LearnToCode #HTML #CSS #JavaScript #PHP #Python
To view or add a comment, sign in
-
More from this author
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development