'5'+1 = '51' & '4'-1 = 3 How is possible in JS!. 🧠 Mastering JavaScript — One Concept at a Time (3/32) I realized something simple but powerful. 📦 What Are Data Types? A data type defines what kind of data is being stored a number, text, boolean, object, and so on. In JavaScript, data types are divided into two main categories: 🔹 1. Primitive Types These are copied by value (they create a separate copy). String, Number, Boolean, Undefined, Null, Symbol, BigInt. Primitives are simple and predictable — changing one doesn’t affect another. 🔹 2. Reference Types (Non-Primitive) These are copied by reference, not by value. Object, Array, Function. Instead of copying the actual data, JavaScript copies the memory reference. That’s why modifying one object can sometimes affect another variable pointing to the same object — and that’s where many beginners get confused. 🔍 The typeof Operator JavaScript gives us a tool to check types — typeof. Most results are straightforward: string → "string" number → "number" boolean → "boolean" undefined → "undefined" But then there’s one famous quirk: 👉 typeof null returns "object" This is actually a long-standing JavaScript bug — and it still exists today. Understanding this prevents a lot of confusion during debugging. 🔁 Type Coercion (The Sneaky Part) JavaScript sometimes automatically converts types during operations. For example: When a string and number are added together, JavaScript may perform concatenation instead of addition. Subtraction forces numeric conversion. Booleans, null, and undefined can also behave unexpectedly in arithmetic operations. This automatic behavior is called type coercion — and it’s one of the most misunderstood parts of JavaScript. Instead of memorizing outputs, I’m now trying to understand: How values are stored How they are copied How JavaScript decides to convert them That clarity changes everything. What was the most confusing type behavior you faced when learning JavaScript? #JavaScript #LearningInPublic #WebDevelopment #FrontendDevelopment #MasteringJavaScript
More Relevant Posts
-
𝗨𝗻𝗱𝗲𝗿𝗦𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝗮𝗻𝗱 𝗗𝗮𝘁𝗮 𝗧𝘆𝗽𝗲𝘀 𝗶𝗻 𝗝𝗮𝗙𝗮𝘀𝗰𝗿𝗶𝗽𝘁 You start with JavaScript, write a few lines of code, and it works. But soon you realize that variables and data types are key. If you skip these basics, your code becomes a guessing game. You end up using console.log() everywhere to understand what's happening. So, before you move deeper into JavaScript, you need to understand variables and data types. You will learn: - What variables are and why you need them - How to declare variables using var, let, and const - Primitive data types like string, number, and boolean - The differences between var, let, and const - What scope means in JavaScript A variable is a name used to store a value. You can access the value by using the variable's name. For example: let count = 1; Here, count is the variable name and 1 is the value. Good variable names should be short and descriptive, like clickButton or userAge. You create a variable in JavaScript using let, const, or var. Example: let count = 1; This declares a variable called count and assigns the value 1 to it. In JavaScript, data types define what kind of value a variable can store. Think of data types like containers: - A string holds text - A number holds a value - A boolean holds true or false JavaScript data types include: - String - Number - Boolean - Null - Undefined Let and const are commonly used in modern JavaScript. Use const by default and let when the value needs to change. Avoid using var. Understanding scope is also important. Scope means where a variable can be accessed in your code. A variable declared with var is only accessible inside the function where it was declared. Let and const work inside a block {}. Mastering variables and data types makes learning more advanced topics easier. Take time to practice writing small examples and experimenting with console.log(). Source: https://lnkd.in/gyY3cNir
To view or add a comment, sign in
-
💡 𝘼 𝙎𝙢𝙖𝙡𝙡 𝙅𝙖𝙫𝙖𝙎𝙘𝙧𝙞𝙥𝙩 𝙎𝙠𝙞𝙡𝙡 𝙏𝙝𝙖𝙩 𝙎𝙖𝙫𝙚𝙨 𝙖 𝙇𝙤𝙩 𝙤𝙛 𝙏𝙞𝙢𝙚: 𝙍𝙚𝙜𝙚𝙭 After around 2 years of working in frontend development, one thing I’ve realized is that small tools can make a big difference. One of them is Regex (Regular Expressions). At first, Regex looked confusing to me: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ But once I understood the basics, it became extremely useful for working with text in web applications. 🚀 Where Regex helps in real projects ✔ Validating form inputs (email, password, phone number) ✔ Cleaning user input ✔ Extracting numbers or patterns from text ✔ Search and replace operations ⚡ Example – Check if a string contains numbers /\𝘥+/.𝘵𝘦𝘴𝘵("𝘖𝘳𝘥𝘦𝘳 𝘐𝘋: 12345") // 𝘵𝘳𝘶𝘦 \𝘥 → 𝘮𝘢𝘵𝘤𝘩𝘦𝘴 𝘥𝘪𝘨𝘪𝘵𝘴 + → 𝘰𝘯𝘦 𝘰𝘳 𝘮𝘰𝘳𝘦 𝘥𝘪𝘨𝘪𝘵𝘴 🧠 A few Regex symbols every JavaScript developer should know 1️⃣ \d → digit (0–9) 2️⃣ \w → word character 3️⃣ \s → whitespace 4️⃣ + → one or more 5️⃣ * → zero or more 6️⃣ ^ → start of string 7️⃣ $ → end of string Regex might look intimidating at first, but learning a few patterns can make text processing much easier and cleaner in JavaScript applications. Still learning, still improving 🚀 What’s a small JavaScript concept that made your development workflow easier? #JavaScript #Regex #FrontendDevelopment #WebDevelopment #Learning #CodingTips
To view or add a comment, sign in
-
🚀 New Blog Alert: Understanding Variables, Data Types & Scope in JavaScript I’ve written a beginner-friendly blog explaining one of the most important foundations of JavaScript: 📦 What is a variable (the “labeled box” concept) 📊 Primitive vs Non-Primitive data types 🔎 Why choosing the right data type matters 🛠 Difference between var, let, and const 🌍 Understanding Global, Function, and Block Scope In this blog, I explained everything in simple terms with practical examples so that beginners can clearly understand how JavaScript handles data and memory. These concepts are the building blocks of writing clean, efficient, and dynamic JavaScript code. Mastering them makes advanced topics much easier to learn. If you're starting your JavaScript journey or revising fundamentals, this will definitely help. I’d love your feedback and thoughts! 💬 #JavaScript #WebDevelopment #Programming #Coding #FrontendDevelopment #Learning #Beginners 👉 Read the full blog here: https://lnkd.in/gtW4R4dG
To view or add a comment, sign in
-
Understanding the difference between map() method and Map in JavaScript 40 minutes. One capital letter. Not a missing semicolon. Not broken logic. Not a failed API call. Just map vs Map. JavaScript doesn't care about your confidence. It cares about your precision. Here's the difference, simply put: map() - lowercase, An array method. It loops through your array and transforms each item, returning a brand new array. Think of it as a data processor. [1,2,3].map(n => n *10) -> [10, 20, 30] Map - uppercase, A data structure. It stores information as key-value pairs, and unlike regular objects, it accepts any data type as a key, preserves the exact order items were added, and comes with clean built-in methods like .set(), .get(), and .has(). One word. Two very different jobs. map() transforms. Map stores. The best developers aren't the ones who never make small mistakes, they're the ones who understand why the mistake happened. Has a tiny detail in JavaScript ever cost you real time? Share it in the comments. If this saved you a future headache, repost so it saves someone else's too.
To view or add a comment, sign in
-
𝗧𝗵𝗲 𝗕𝗮𝘀𝗶𝗰𝘀 𝗼𝗳 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝗮𝗻𝗱 𝗗𝗮𝘁𝗮 𝗧𝘆𝗽𝗲𝘀 JavaScript is a powerful language that powers many applications. To get started with JavaScript, you need to understand variables and data types. A variable is a named container that stores data values. You can think of it as a box with a name tag. You put something inside the box, and when you need it, you look inside the box. You need variables to reuse data, track changes, and make your code readable. For example, you can store a user's name or score in a variable. There are three ways to declare variables in JavaScript: var, let, and const. - var: can be redeclared and updated, but it's not recommended. - let: cannot be redeclared, but can be updated. - const: cannot be redeclared or updated. When to use each: - Use const by default to prevent accidental reassignment. - Use let when you know the value will change. JavaScript has several data types, including: - Number: represents both integer and floating point numbers. - String: a sequence of characters used to represent text. - Boolean: has only two values: true or false. - Null: representsnothing or "empty". - Undefined: means a variable has been declared but no value has been assigned. Understanding scope is also important in JavaScript. Scope determines where a variable is accessible. - Global scope: variables are accessible everywhere. - Function scope: variables are accessible only inside a function. - Block scope: variables are accessible only inside a block. To get better at JavaScript, create your own variables, experiment with var, let, and const, and try different data types. Practice is key to mastering JavaScript. Source: https://lnkd.in/gMgjyT-m
To view or add a comment, sign in
-
𝗧𝗵𝗶𝘀 𝗜𝘀 𝗔 𝗟𝗶𝗻𝗸𝗲𝗱𝗜𝗻 𝗣𝗼𝘀𝘁 JavaScript has many small features that can make your code cleaner and easier to maintain. You can use these features to write better code. Here are some tricks to help you: - Remove duplicates from an array with Set - Convert anything to a boolean with double negation - Swap variables with destructuring - Use optional chaining to avoid long nested checks - Provide fallback values easily with ?? - Use console.table for debugging Some other tricks include: - Using Array.from to create an array - Using flat to flatten an array - Using Object.entries to get an array of key-value pairs - Using Object.fromEntries to create an object from an array - Using at to get the last element of an array - Using filter to remove falsey values - Using console.table to display data in a readable table - Using Promise.all to run multiple promises at the same time - Using debounce to delay a function - Using Math.random to generate a unique string - Using includes to check if an array includes a value - Using structuredClone for deep cloning You don't need to memorize all of these tricks. But using them can help you write cleaner code, reduce boilerplate, and improve readability. What's your favorite JavaScript trick? Share it in the comments. Source: https://lnkd.in/gUdrjCvm
To view or add a comment, sign in
-
📘 Day 70: JavaScript Functions 🔹 Functions in JavaScript • A function is a reusable block of code • Created using the function keyword • Runs only when the function name is called 🔸 Parameters & Arguments • Parameters → variables in function definition • Arguments → values passed when calling • Usually should match in count 🔸 Function Expression (Function in Variable) • Functions can be stored in variables • Call using the variable name 🔸 Constructor Function • Created using new Function() • Written in one line • Must use return to send result back 🔸 Rest Parameter (...) • Collects multiple arguments into one parameter • Stored as an array • Can access with index numbers 🔸 Default Parameters • Assign default values in case arguments are missing • Prevents undefined values • Example: function add(x, y=10) 🔸 Arrow Functions (⇒) • Short and modern function syntax • Similar to Python lambda • Great for one-line logic 🔸 map() • Applies a function to every array element • Returns a new array • Used for transforming data 🔸 filter() • Returns only elements that match a condition • Single input → multiple outputs 🔸 reduce() • Reduces array to a single value • Uses two parameters (accumulator & current) • Useful for sum, max, totals 🔸 Function Scope ✅ Global Scope • Accessible everywhere ✅ Local Scope • Accessible only inside function 🔸 Object Methods & this • this refers to the current object • Used to access object properties • Helps combine keys like full name 🔸 call() Method • Calls a function using another object's data • Allows borrowing methods 🔸 bind() Method • Similar to call • Returns a new function • Stored in a variable and used later ✨ Today focused on mastering JavaScript functions, the backbone of reusable and structured code. Understanding these helps write cleaner, smarter, and more powerful programs. #JavaScript #Day70 #Functions #WebDevelopment #JSBasics #ArrowFunction #MapFilterReduce #CodingJourney #FrontendDevelopment #LearnJavaScript #DeveloperJourney
To view or add a comment, sign in
-
𝗨𝗻𝗱𝗲𝗿𝘀𝘁𝗮𝗻𝗱𝗶𝗻𝗴 𝗩𝗮𝗿𝗶𝗮𝗯𝗹𝗲𝘀 𝗮𝗻𝗱 𝗗𝗮𝘁𝗮 𝗧𝘆𝗽𝗲𝘀 𝗶𝗻 𝗝𝗮𝗵𝗮𝘀𝗰𝗿𝗶𝗽𝘁 You start with JavaScript, write a few lines of code, and it works. But soon you realize that variables and data types are key. If you skip these basics, your code can become a guessing game. You will use console.log() everywhere just to understand what's happening. So, before you move deeper into JavaScript, understand how variables and data types work. Here's what you will learn: - What variables are and why you need them - How to declare variables using var, let, and const - Primitive data types like string, number, and boolean - The differences between var, let, and const - What scope means in JavaScript A variable is a name used to store a value. You can access the value by using the variable's name. For example: let count = 1, where count is the variable name and 1 is the value. Good variable names should be short and descriptive, like clickButton or userAge. To create a variable, you use let, const, or var. For example: let count = 1, which declares a variable and assigns a value. The = symbol assigns a value to a variable. In JavaScript, data types define what kind of value a variable can store. Think of data types like containers: - A string holds text - A number holds a value - A boolean holds true or false JavaScript data types include: - String - Number - Boolean - Undefined - Null - BigInt - Symbol - Object - Array - Function var, let, and const have different features: - var allows redeclaration and change of value - let does not allow redeclaration but allows change of value - const does not allow redeclaration or change of value Scope means where a variable can be accessed in your code. A variable declared with var is accessible inside a function. let and const are accessible inside a block. Understanding variables and data types is key to learning more about JavaScript. Take time to practice and experiment with console.log() to see how values change. Master these basics and your JavaScript journey will become smoother. Source: https://lnkd.in/gyY3cNir
To view or add a comment, sign in
-
Today I learned something interesting about fetching data in JavaScript. When we use fetch(), many beginners notice that it usually has two .then() methods. At first it looks unnecessary, but there is a clear reason behind it. The first .then() handles the HTTP response returned by fetch(). The second .then() is used to convert that response into actual JSON data using response.json(). Example: fetch("API_URL") .then(response => response.json()) .then(data => { console.log(data); }); While revising this concept, I also learned a cleaner and more modern approach using async/await, which makes asynchronous code easier to read and understand. async function getData() { const response = await fetch("API_URL"); const data = await response.json(); console.log(data); } Both approaches work the same way internally using Promises, but async/await makes the flow feel more natural. Small concepts like these help in writing cleaner and more maintainable JavaScript code. #JavaScript #WebDevelopment #AsyncJavaScript #FetchAPI #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
JavaScripts some Importand topic and Advanced If you are learn, you are master in javascript. 1. Core (Fundamental) Objects Object – Base object for all JavaScript objects Function – Functions are special objects Boolean – Wrapper for true/false Symbol – Unique identifier Error – Base object for errors 2. Numbers & Dates Number – Number wrapper object BigInt – Large integers Math – Mathematical operations Date – Date and time handling 3. Text Processing String – String wrapper object RegExp – Regular expressions 4. Indexed Collections Array – Ordered collection Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array BigInt64Array BigUint64Array 5. Keyed Collections Map – Key-value pairs Set – Unique values WeakMap – Weakly referenced keys WeakSet – Weakly referenced values 6. Structured Data JSON – JSON parsing and stringifying 7. Control Abstraction Objects Promise – Asynchronous operations Generator – Generator functions AsyncFunction – Async functions 8. Reflection Reflect – Interceptable operations Proxy – Custom behavior for objects 9. Internationalization Intl – Internationalization API 10. Web Browser Objects (Not Core JS but Important) window – Global object in browser document – DOM document console – Logging localStorage sessionStorage
To view or add a comment, sign in
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