🚀 Using `match()` Method of String Object (JavaScript) The `match()` method of a string object searches the string for a match against a regular expression. If the `g` flag is present, it returns an array of all matching substrings. If the `g` flag is absent, it returns the same type of array as `exec()`. If no match is found, it returns `null`. It's a versatile method for extracting matching substrings from a string. #JavaScript #WebDev #Frontend #JS #professional #career #development
JavaScript match() Method Explained
More Relevant Posts
-
most developers don't know the difference between null , undefined and "" and it's breaking their React forms silently. - always initialise string state with ' ' not undefined - always initialise array state with [ ] not undefined - always initialise object state with { } not undefined here's why it matters beyond the warning: - undefined means "this was never set" - null means "this was intentionally set to nothing" - ' ' means "this exists but is currently empty" React treats these three things completely differently when rendering. your form works locally because you fill it in immediately. it breaks in production because someone submits without touching a field. initialise your state properly. #reactjs #typescript #webdevelopment #buildinpublic #javascript
To view or add a comment, sign in
-
-
🚀 Array Methods: splice and slice (JavaScript) The `splice()` method modifies an array by removing or replacing existing elements and/or adding new elements in place. It takes the starting index and the number of elements to remove as arguments, and optionally, new elements to insert. The `slice()` method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. `slice()` does not modify the original array. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
Quick JavaScript Question for Developers Do you think this is true or false? [] == ![] I actually came across this while working on a feature. At one point, my condition was behaving in a way I didn’t expect… and this was the reason behind it. 👉 The result is: true Why is it true? It looks like a small thing…But the impact? [] is truthy → so ![] becomes false Now it becomes: [] == false JavaScript then converts both sides to numbers: false → 0 [] → "" → 0 So finally: 0 == 0 → true Always prefer === to avoid these surprises #javascript #coding #webdevelopment #developers #js
To view or add a comment, sign in
-
-
🚀 The 'this' Keyword (JavaScript) The `this` keyword in JavaScript refers to the context in which a function is executed. Its value depends on how the function is called. In a regular function call, `this` typically refers to the global object (window in browsers, global in Node.js). However, when a function is called as a method of an object, `this` refers to that object. Understanding the different contexts of `this` is vital for working with objects and methods. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
🚀 Lexical Scope and Closures (JavaScript) Lexical scope (also known as static scope) means that a function's scope is determined by its position in the source code. Closures are functions that have access to variables from their surrounding scope, even after the outer function has finished executing. This is because the inner function 'closes over' the variables in its lexical environment. Closures are a powerful feature of JavaScript, enabling data encapsulation and state preservation. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
Hey JavaScript devs 👋 Did you know `this` can silently disappear in 3 very common situations? 1. Detaching a method from its object const fn = obj.greet; fn(); // this → undefined 💀 2. Passing a method as a callback setTimeout(obj.greet, 0); // this → gone [1,2,3].forEach(obj.process); // same story 3. Arrow function in an object literal const obj = { name: 'Pavel', greet: () => console.log(this.name) // this → global, not obj }; The fix is always one of three things: `.bind()`, a wrapper arrow function, or class field arrow methods. Which one bit you the hardest? Drop it in the comments 👇 #JavaScript #WebDev #Frontend #JS
To view or add a comment, sign in
-
-
🚀 Preventing Default Event Behavior with `preventDefault` (JavaScript) Many DOM events have default behaviors associated with them, such as submitting a form or following a link. You can prevent these default behaviors using the `preventDefault()` method of the event object. This is useful for overriding the default behavior and implementing custom logic. For example, you can prevent a form from submitting and instead validate the input fields using JavaScript. Use `preventDefault()` judiciously, as it can sometimes disrupt the expected user experience. #JavaScript #WebDev #Frontend #JS #professional #career #development
To view or add a comment, sign in
-
-
💡 JS Trick: Infinite Currying This question is often asked in interviews to test your understanding of closures + function chaining. 👉 Infinite currying means calling a function repeatedly like sum(1)(2)(3)(4)... and getting the final result. ✅ How it works: 🔹 Each call stores value using closure 🔹 Returns a function again 🔹 Final value comes when evaluated 🎯 Shortcut to Remember: 👉 Function keeps returning function until final result #JavaScript #CodingInterview #Currying #Closures #Frontend #WebDevelopment #JS
To view or add a comment, sign in
-
-
💡 𝗧𝗶𝗽 𝗼𝗳 𝘁𝗵𝗲 𝗗𝗮𝘆 — 𝗥𝗲𝗮𝗰𝘁 𝗗𝗶𝗱 𝘆𝗼𝘂 𝗸𝗻𝗼𝘄? In React, 𝗳𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗱𝗲𝗳𝗶𝗻𝗲𝗱 𝗶𝗻𝘀𝗶𝗱𝗲 𝗰𝗼𝗺𝗽𝗼𝗻𝗲𝗻𝘁𝘀 𝗮𝗿𝗲 𝗿𝗲𝗰𝗿𝗲𝗮𝘁𝗲𝗱 𝗼𝗻 𝗲𝘃𝗲𝗿𝘆 𝗿𝗲𝗻𝗱𝗲𝗿. This means passing them as props can trigger unnecessary re-renders in child components. 🔧 𝗕𝗲𝘀𝘁 𝗽𝗿𝗮𝗰𝘁𝗶𝗰𝗲: - Use "useCallback" to memoize functions when passing them down - Only do this when necessary (e.g., with "React.memo" or dependency arrays) Not every function needs memoization—but knowing when it matters is key. #React #ReactJS #FrontendDevelopment #JavaScript #WebDevelopment #PerformanceOptimization #SoftwareEngineering #CodingTips #FullstackDeveloper
To view or add a comment, sign in
-
-
What is a closure in JavaScript? A closure is a function that remembers variables from its outer scope even after that scope has finished executing. Why does this work? - `createCounter` runs once - It creates a variable `count` - The inner function “closes over” that variable - Even after `createCounter` finishes, `count` is still accessible Each time `counter()` runs: → it uses the same preserved state 💡 Closures are everywhere: - React hooks - Event handlers - Memoization - Encapsulation patterns They’re not just a concept — they’re part of how JavaScript manages state. #Frontend #JavaScript #React #WebDevelopment #SoftwareEngineering
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