A small JavaScript detail, but a surprisingly powerful one 💡 Most of us use: num.toString() to convert a number into a string. What’s less commonly discussed is that toString() also accepts a radix (base), which allows the same number to be represented in different numeral systems : num.toString(2) // Binary num.toString(8) // Octal num.toString(16) // Hexadecimal For example: let num = 9; num.toString(2); // "1001" This single method becomes extremely useful when working with: Bit manipulation and binary logic ⚙️ Performance-oriented problem solving A good reminder that many “advanced” solutions are built on a strong understanding of fundamentals. #JavaScript #SoftwareEngineering #ProblemSolving #ContinuousLearning
JavaScript toString() Method with Radix
More Relevant Posts
-
Day 65 – JavaScript String Methods Today I explored advanced JavaScript string methods that are commonly used for text validation, searching, formatting, and manipulation in real-world applications. Topics Covered: startsWith() – Checks whether a string begins with a specific value toUpperCase() – Converts all characters to uppercase toLowerCase() – Converts all characters to lowercase includes() – Verifies whether a specific value exists in a string search() – Finds the index position of a value (returns -1 if not found) concat() – Combines multiple strings in a defined order These methods are especially useful in form validation, search features, filtering data, and user input handling. Understanding them helps write cleaner, more efficient, and readable JavaScript code. #JavaScript #FrontendDevelopment #WebDevelopment #StringMethods
To view or add a comment, sign in
-
n8n expression gotcha: Why your ternary isn't working This looks right but fails: {{ $json.count ? "Has items" : "Empty" }} Problem: 0 is "falsy" in JavaScript. If count is 0, it shows "Empty" even though it's a valid value. Fix - be explicit: {{ $json.count > 0 ? "Has items" : "Empty" }} JavaScript truthy/falsy catches everyone eventually. Full pitfalls list: https://lnkd.in/gs2RKUyp #n8n #automation #javascript
To view or add a comment, sign in
-
💡 Sunday Dev Tip: JavaScript Array Methods Stop writing loops. Use array methods instead! ❌ Traditional Loop: let doubled = []; for (let i = 0; i < numbers.length; i++) { doubled.push(numbers[i] * 2); } ✅ Modern Approach: const doubled = numbers.map(n => n * 2); Master These Methods: → .map() - Transform each element → .filter() - Keep elements that match → .reduce() - Calculate single value → .find() - Get first match → .some() / .every() - Test conditions Your code becomes: ✅ More readable ✅ Less error-prone ✅ Easier to maintain ✅ More functional Which array method do you use most? 💬 #JavaScript #CleanCode #WebDevelopment #CodingTips #ES6
To view or add a comment, sign in
-
JavaScript TDZ — Where are var, let, and const stored? 🧠 When JS runs, it creates an Execution Context ⚙️ with two memory areas: 1️⃣ Global Object Environment 🌍 → var variables go here → attached to the global object (like window in browsers) → auto-initialized with undefined ✅ 2️⃣ Script / Lexical Environment 📦 → let and const go here → block-scoped memory space → memory reserved but not initialized 🚫 (TDZ ⏳) That’s why: var before declaration → undefined let/const before declaration → error ⛔ JS separates them to enforce block scope and reduce bugs 🛡️ #JavaScript #JSCore #ExecutionContext
To view or add a comment, sign in
-
Mastering the Two Sum Algorithm in JavaScript (O(n) solution) Today I implemented the classic Two Sum problem using an optimized approach with Map in JavaScript. Instead of using the naive O(n²) double loop, I used a hash map to reduce the time complexity to O(n). Here is the core idea: 🔍 Why this approach is powerful Single loop → O(n) time complexity Constant-time lookup using a hash map Clean and scalable logic Interview-ready solution I'm currently strengthening my problem-solving and algorithmic thinking skills daily. You can find the full exercises repository here: 👉 https://lnkd.in/ej4fNeZs Consistency > Motivation. Small improvements every day compound over time. #JavaScript #Algorithms #ProblemSolving #WebDevelopment #100DaysOfCode #SoftwareEngineering
To view or add a comment, sign in
-
-
Understanding behavior before blaming the result 2 + 0 = 20 6 + 6 = 66 In JavaScript, the + operator is overloaded. It performs: • Numeric addition when both operands are numbers • String concatenation when one or both operands are strings So: "2" + 0 → 0 is coerced into a string → "20" "6" + "6" → Direct string concatenation → "66" This isn’t incorrect logic. It’s deterministic behavior defined by the language specification. The lesson isn’t about math. It’s about type awareness. In production systems, relying on implicit coercion introduces ambiguity. Explicit conversion (Number(), parsent(), strict typing) reduces risk. Predictable systems come from predictable inputs. #JavaScript #TypeCoercion #SoftwareDesign #WebDevelopment #EngineeringPrinciples
To view or add a comment, sign in
-
-
Debugging JavaScript nested for-loops with querySelector DOM manipulation involves checking your functions, arrays, syntax, variable declaration, and structure. That's a lot, even for simple functionality. The attached screenshot is the code (manually typed) that looks clean, but does not modify the HTML <li> content one bit. The error did not appear to be in the HTML side. Eventually I commented this code out and restarted, using different variable names, and the code produced the expected output. The issue might have been parameters or arguments not being called properly, or some other misspelling or missing/extra character.
To view or add a comment, sign in
-
-
Follow-up to yesterday’s JavaScript `this` question 👇 Yesterday’s output was: 10 2 undefined undefined The issue was: • lost `this` context • accidental global variable usage So what if we want **ALL calls to always print 10**? Here’s a clean and correct solution 👇 Output: 10 10 10 10 🧠Why this works • We always access a through this.a • No accidental mutation of global variables • bind(obj) permanently fixes the context • call(obj) explicitly sets the correct context No matter how the function is invoked, this always points to obj. 🔑 Key Takeaway If a function depends on `this`, make the binding explicit. #JavaScript #ThisKeyword #CallBindApply #InterviewQuestions #FrontendDeveloper #MERNStack
To view or add a comment, sign in
-
-
What’s the difference between var, let, and const?” Beginner answer: “Scope and reassignment.” Stronger answer: “var is function-scoped and initialized during hoisting, which can cause scope leakage and redeclaration issues. let and const are block-scoped, exist in the Temporal Dead Zone before initialization, and prevent accidental redeclarations. const also prevents reassignment of the binding.” That’s the difference between memorizing and understanding. Still building foundations. Because frameworks change. Core JavaScript doesn’t. #JavaScript #TechInterviews #FrontendEngineer #JSDeepDive #ProgrammingFundamentals #CareerGrowth
To view or add a comment, sign in
-
Can you spot the bug? 👀 This screenshot shows JavaScript code reconstructed from its AST and replayed from the Utopixia network. The runtime throws a simple error: “Expression expected” The code looks fine at first glance. But a single missing detail introduced during code generation breaks execution. When you stop storing files and start storing structure, your bugs change nature. Can you see what’s wrong? 😄 PS: The code quality itself isn’t the point here. This is intentionally unstructured JavaScript generated by an LLM, used to stress-test AST parsing and code reconstruction at scale. #BuildInPublic #Developers #JavaScript #AST #DistributedSystems
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