While learning JavaScript deeply, I came across a concept that completely changed how I think about variables. In JavaScript, variables don’t have types — values do. Unlike languages like Java or C++, where a variable’s type is fixed, JavaScript variables are just containers that can reference different kinds of values over time. Example: let x = 10; // number x = "hello"; // string x = true; // boolean The variable x stays the same, but the value (and its type) changes. Understanding this simple idea makes many JavaScript behaviors — like dynamic typing and type coercion — much easier to reason about. I wrote a short post explaining this concept clearly. Check it out here: https://lnkd.in/gMZ-ESa3
JavaScript Variables Don't Have Types, Values Do
More Relevant Posts
-
One of the fascinating things about JavaScript is how good a language it is despite having been thrown together in ten days with the bizarre constraint that it look like Java because Sun and Netscape were flirting. As I try to refine the developer experience of tjs to a finely honed edge I have the luxury of having no user base and a tireless peon who is willing to update all test code, examples, and documentation on a whim. Yesterday I changed the function signature syntax to be more intuitive for typescript coders. Claude implemented it as a deprecation and I said no, just purge the old syntax. We have no users so why make our code more complex or our examples ambiguous. It’s amazing to me that JavaScript got as far as it did with its obvious flaws (and strengths) without getting some crucial fixes before there were too many stakeholders to satisfy. typeof null == “object”… really? Semicolon insertion?! And it’s not like HyperCard hadn’t walked the same path more successfully nearly ten years earlier. HyperTalk was already compiling to assembler and writing system extensions at that point.
To view or add a comment, sign in
-
JavaScript Doesn't Have Classes! Yes, that's correct. Anyone who started using JavaScript after 2015 will be very confused by this statement. "But I saw the class syntax in the intro course I took when I started programming!" Which would also be accurate. JavaScript has a syntax for classes, but under the hood, no class in the Java/C++ sense is being declared. Don't believe me? Go run this in your browser console: class Test { constructor() { this.prop = "test"; } } console.log(typeof Test); Yes, it's a function. JavaScript classes essentially do two things: create a constructor function that works with the "new" keyword, and set up a prototype object (more on that another time). "Okay, but it's still basically a class." No, not really. Try this code (hopefully you tried the one above first): let x = new Test(); Now you have a Test object with one property, "prop". Now do this: x.newprop = "newprop"; This runs. In most other languages, this would be grounds for the compiler to crash your IDE out of pure spite. It runs in JavaScript because the class was never acting as a blueprint, it was just a special constructor function all along. If you've always been confused by the __proto__ property when checking Javascript objects and too scared to ask what it is, well it's part of the same conspiracy, I will be writing about it in my next post #javascript #webdevelopment #programming
To view or add a comment, sign in
-
-
I have started a challenge today to finish Javascript in 1 week. #DAY1 ✨ Today I have done these basic questions of Java Script. Print your name, age Create variables and check typeof 1. Print Name & Age let name = "Rahul"; let age = 21; console.log("Name:", name); console.log("Age:", age); Output Name: Rahul Age: 21 2. Check typeof of Variables let name = "Rahul"; let age = 21; let isStudent = true; console.log(typeof name); // string console.log(typeof age); // number console.log(typeof isStudent); // boolean 3. More typeof Examples let x; let y = null; let arr = [1, 2, 3]; let obj = {a: 1}; console.log(typeof x); // undefined console.log(typeof y); // object (important JS bug ⚠️) console.log(typeof arr); // object console.log(typeof obj); // object typeof null = "object" kyun aata hai typeof null = "object" ❓ (Why?) JavaScript let y = null; console.log(typeof y); // object 👉 Expected kya hona chahiye? "null" 👉 But actual output aata hai: "object" 💡 Reason (Simple Explanation) Ye JavaScript ka old bug hai, jo aaj tak fix nahi hua. 🔧 Internal reason: Jab JavaScript banayi gayi (1995 me), us time pe: Values ko binary format me store kiya jata tha Objects ka type code = 0 hota tha null ka representation bhi 0 tha 👉 Isliye: null → object treat ho gaya ❌ ⚠️ Important Point Ye bug hai, feature nahi But ab isse change nahi kar sakte (backward compatibility issue) 🧠 Interview / Exam Line In JavaScript, typeof null returns "object" due to a historical bug in the language, where null was incorrectly classified as an object. ✅ Correct Way to Check null let y = null; if (y === null) { console.log("y is null"); } 👉 Always use: === null #coding #consistency #CS #practice
To view or add a comment, sign in
-
Day 13 of Learning JavaScript 💻 Today I practiced accessing and modifying object properties. Example: user.name = "New Name" This is useful when working with dynamic data. Feels good to understand how real apps update data. #javascript #frontenddeveloper
To view or add a comment, sign in
-
As a programmer, many beginners asked me this question: 'Java vs JavaScript, which is better?' Wrong comparison. JavaScript is built for adaptability WHILE Java is built for reliability. JavaScript lets you prototype fast, iterate quickly and pivot without heavy constraints. Perfect for environments where speed, experimentation and rapid delivery matter. Java enforces structure, strong typing and clear architecture, reducing errors as systems grow. That’s why it dominates in large-scale, long-term enterprise systems. One lets you move fast and adjust on the fly WHILE the other forces you to think ahead and build for the future. So the debate isn’t about better. It’s about trade-offs: speed and flexibility OR stability and predictability Which one matters more depends on your context, not the language. So ask yourself: Are you trying to build fast… or build something that won’t break at scale? #programming #javascript #informationtechnology #softwaredeveloper #javascript #webprogramming #IT #coding #informationsystems
To view or add a comment, sign in
-
-
🚀 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 𝐒𝐞𝐫𝐢𝐞𝐬 — 𝐀𝐫𝐭𝐢𝐜𝐥𝐞 𝟎𝟐 𝙇𝙖𝙗𝙚𝙡𝙚𝙙 𝘽𝙤𝙭𝙚𝙨: 𝙐𝙣𝙙𝙚𝙧𝙨𝙩𝙖𝙣𝙙𝙞𝙣𝙜 𝙑𝙖𝙧𝙞𝙖𝙗𝙡𝙚𝙨 𝙖𝙣𝙙 𝘽𝙖𝙨𝙞𝙘 𝙏𝙮𝙥𝙚𝙨 𝙞𝙣 𝙏𝙮𝙥𝙚𝙎𝙘𝙧𝙞𝙥𝙩 𝐕𝐚𝐫𝐢𝐚𝐛𝐥𝐞𝐬 in programming are like boxes that store data. In real life, we use labels to easily identify what’s inside a box, right? Because if a box has a label, it’s easy to understand what’s inside. If it doesn’t, things get confusing. The same concept applies to programming. But in 𝐉𝐚𝐯𝐚𝐒𝐜𝐫𝐢𝐩𝐭, these boxes don’t have labels. So inside a single JavaScript variable, you can store: 👉 a 𝙣𝙪𝙢𝙗𝙚𝙧 👉 a 𝙨𝙩𝙧𝙞𝙣𝙜 👉 a 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 This flexibility might seem useful… But it’s one of the main reasons behind 𝐫𝐮𝐧𝐭𝐢𝐦𝐞 𝐞𝐫𝐫𝐨𝐫𝐬. 💡 𝐓𝐲𝐩𝐞𝐒𝐜𝐫𝐢𝐩𝐭 solves this problem using 𝙩𝙮𝙥𝙚𝙨. It allows you to add labels to your variables: 👉 If you only need to store 𝙩𝙚𝙭𝙩 inside a variable, you can use the 𝙨𝙩𝙧𝙞𝙣𝙜 type. 👉 If you only need to store 𝙣𝙪𝙢𝙗𝙚𝙧𝙨 inside a variable, you can use the 𝙣𝙪𝙢𝙗𝙚𝙧 type. 👉 If you only need to store 𝙩𝙧𝙪𝙚/𝙛𝙖𝙡𝙨𝙚 inside a variable, you can use the 𝙗𝙤𝙤𝙡𝙚𝙖𝙣 type. By using these types: ✅ Your code becomes safer ✅ Bugs are reduced ✅ Developer experience improves In this article, I explain: 📦 What variables really are 🏷️ How type labels work in TypeScript 🧠 What Type Inference is ⚙️ The role of the TypeScript compiler 📖 Read the full article here: 👉 https://lnkd.in/g725SZP4 #TypeScript #JavaScript #WebDevelopment #Programming #LearningInPublic #SoftwareEngineering🚀
To view or add a comment, sign in
-
-
𝗧𝗵𝗲 𝗕𝗮𝘀𝗶𝗰𝘀 𝗼𝗳 𝗝𝗩𝗠 𝗮𝗻𝗱 𝗩𝟴 You want to know how Java and JavaScript work. Let's break it down. Programming languages are classified into two main types: statically typed and dynamically typed. - Statically typed languages check types before execution. - Dynamically typed languages determine types at runtime. There are also two main execution models: compiled and interpreted languages. - Compiled languages translate code into machine code before execution. - Interpreted languages execute code directly. But here's the thing: most languages use a hybrid approach. They combine compilation and interpretation to achieve better performance. This is where Just-In-Time (JIT) compilation comes in. It analyzes the code, identifies hot paths, and compiles them to machine code for better performance. The Java Virtual Machine (JVM) and V8 engine are two examples of this hybrid approach. - The JVM is a virtual machine that runs Java bytecode. - The V8 engine is a JavaScript engine that executes ECMAScript and WebAssembly specifications. So, what's the difference between JVM and V8? - The JVM is an abstract machine that runs bytecode, while V8 is a real implementation of the ECMAScript and WebAssembly specs. - The JVM has a public spec for its bytecode, while V8 does not. In the end, understanding how Java and JavaScript work can help you appreciate the complexity of programming languages. You can learn more about the JVM and V8 engine through the following resources: Source: https://lnkd.in/gi8Pne8w Optional learning community: https://lnkd.in/gmwngSRR
To view or add a comment, sign in
-
🚀 Just published a new blog on Understanding Variables and Data Types in JavaScript. In this article, I explain the basics of variables, why they are needed in programming, and how to declare them using var, let, and const. I also covered important primitive data types like string, number, boolean, null, and undefined with simple beginner-friendly examples. 📖 Read the full article here: https://lnkd.in/gzXWjzJG Inspired by the amazing teaching of Hitesh Choudhary Sir and Piyush Garg Sir from Chai Aur Code. ☕💻 #javascript #webdevelopment #learninginpublic #chaiAurCode
To view or add a comment, sign in
-
Coming from languages like C/C++ or Java, JavaScript can feel a bit like magic. There’s no dedicated, pre-run compiler—everything happens on the fly! So, what actually happens under the hood when a simple JavaScript program runs? 1. The Translation Phase (From Code to Machine Language) Parsing: The engine's parser checks for syntax errors, breaks the code into tokens (keywords, Identifiers, operators, etc.), and builds a tree structure called the Abstract Syntax Tree (AST). Interpretation: The engine translates the AST into Bytecode (an intermediate language) and execution starts immediately using this Bytecode line-by-line. JIT Compilation: As the Bytecode runs, a "Profiler" watches the code. If it notices a specific function is being used over and over again(called "hot" code), it passes that specific bytecode to the JIT Compiler. 2. Where Does Everything Live? (Memory) While the program is loaded into RAM, memory is split into two main areas: The Heap: Stores complex reference types (Objects, Arrays, Functions) and program data. The Stack: Stores primitive values, memory references (addresses), and the Execution Contexts. 3. The Execution Phase (How it Runs) Whenever a JS program runs, a Global Execution Context (GEC) is pushed onto the Call Stack. JS engine is single-threaded, meaning it executes synchronously, line-by-line. The GEC creation happens in two distinct phases: 🧠Memory Creation Phase: The engine scans the code and allocates memory. Functions get their complete bodies stored. Variables declared with var are initialized as undefined, while let and const variables are placed in the Temporary Dead Zone (TDZ). 💻 Code Execution Phase: The engine executes the program top-to-bottom. Whenever a new function is invoked, a brand new Execution Context is created and pushed onto the Call Stack to handle it! Have you ever looked into how your favorite programming language executes under the hood? Let me know in the comments! 👇 #JavaScript #WebDevelopment #CodingJourney #JSEngine #SoftwareEngineering #TechTips#
To view or add a comment, sign in
-
-
Unpopular opinion: JavaScript is easier to start… but harder to truly master than Java. Because JavaScript lets you get away with bad programming habits. Java doesn’t. One hides your mistakes. The other exposes them immediately. That’s why many developers feel “stuck” later. Agree or disagree? #programming #java #javascript #softwareengineering #webdeveloper #growth #developer
To view or add a comment, sign in
More from this author
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