100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
HomeBlogUnderstanding this in JavaScript
Programming

Understanding this in JavaScript

SV

SkillVeris Team

Engineering Team

Aug 1, 2025 9 min read
Share:
Understanding this in JavaScript
Key Takeaway

The value of this in JavaScript is decided by how a function is called, not where it is written, and follows four predictable rules.

In this guide, you'll learn:

  • In a regular function called on an object, this is that object; called plainly, this is undefined in strict mode.
  • Arrow functions have no own this — they inherit it from the surrounding scope, which fixes most callback problems.
  • call, apply, and bind let you set this explicitly when you need to.
  • When a method is passed as a callback, it loses its this unless you bind it or wrap it in an arrow.

1What Does this Mean in JavaScript?

In JavaScript, this is a special keyword whose value is determined at call time — by how a function is invoked, not by where it was defined. That single fact explains almost every confusing case. The same function can have a different this depending on whether you call it as a method, plainly, with new, or with an explicit binding.

Once you accept that this is about the call, not the definition, the rest is a small set of rules. There are four binding patterns, and every situation falls into one of them. Learning to spot which pattern applies is the whole skill.

2Rule 1: Method Calls

When you call a function as a method — with an object before the dot — this refers to that object. This is the most intuitive case and the one people rely on when writing classes and object methods. The object to the left of the dot at the moment of the call wins.

  • const user = { name: 'Ada', greet() { return 'Hi ' + this.name } }
  • user.greet() # this is user, returns 'Hi Ada'
  • const other = { name: 'Grace', greet: user.greet }
  • other.greet() # this is other, returns 'Hi Grace'

🔑Key Idea

It is the object at the call site — the thing before the dot — that sets this, not the object where the method was originally defined.

3Rule 2: Plain Function Calls

When you call a function on its own, with nothing before it, there is no object to bind to. In strict mode — which modules and classes use by default — this is undefined. In old non-strict code it falls back to the global object, which is a frequent source of silent bugs.

This is exactly what happens when a method gets detached and called as a standalone function, such as when you pass it to setTimeout. The dot is gone, so the method binding is gone with it, and this is no longer the object you expected.

⚠️Watch Out

Passing obj.method as a callback strips its this. By the time it runs, it is a plain call, so this is undefined. Bind it or wrap it in an arrow first.

4Rule 3: Arrow Functions Inherit this

Arrow functions break the pattern deliberately. They have no this of their own, so they use the this of the scope where they were defined. This lexical behaviour is why arrows are perfect for callbacks inside methods — the callback keeps pointing at the same object as the method around it.

This is the modern replacement for the old const self = this trick. Instead of stashing a reference, you write the callback as an arrow and this simply flows through from the enclosing method.

  • setInterval(() => this.tick(), 1000) # arrow keeps the method's this
  • arr.map(x => this.transform(x)) # this stays the enclosing object

5Rule 4: call, apply, and bind

Sometimes you want to set this manually. Three methods let you do that. call and apply invoke the function immediately with a this you choose — call takes arguments individually, apply takes them as an array. bind returns a new function with this permanently fixed, which you call later.

  • greet.call(user, 'hello') # runs now, this is user, args listed
  • greet.apply(user, ['hello']) # runs now, args as an array
  • const bound = greet.bind(user) # returns a new function, this fixed to user
  • button.addEventListener('click', handler.bind(this)) # keep this in a callback

When to Use bind

bind shines when you need to hand a method to another function that will call it later, such as an event listener. It locks in this so the method behaves correctly no matter how it is invoked.

6this With the new Keyword

There is a fifth situation worth naming: calling a function with new. When you invoke a constructor function or a class with new, JavaScript creates a fresh object and sets this to point at it inside the function. This is how instances get their own properties.

This rule quietly underlies every class you write. Inside a constructor, this is the object being built, which is why assigning this.name gives each instance its own name. Forgetting new means this is not the new object, so the assignments go somewhere unexpected.

  • class User { constructor(name) { this.name = name } }
  • const u = new User('Ada') # this inside the constructor is the new object
  • u.name # 'Ada', stored on the instance

7Common Mistakes to Avoid

Nearly all this confusion comes from a few recurring situations. Recognising them makes the fix obvious.

  • Passing a method as a callback and losing this — bind it or wrap it in an arrow.
  • Using a regular function as an array-method callback inside a method and finding this undefined.
  • Defining an object method as an arrow, so this points at the outer scope instead of the object.
  • Assuming this is set by where the function is written rather than how it is called.
  • Forgetting that strict mode makes a plain call's this undefined rather than the global object.

8Key Takeaways

The value of this always comes down to the call, and to four rules.

  • this is determined by how a function is called, not where it is defined.
  • Method calls set this to the object before the dot.
  • Plain calls give undefined in strict mode; arrows inherit this from their scope.
  • call and apply set this and run immediately; bind returns a function with this fixed.
  • Losing this in callbacks is the most common bug — bind or use an arrow to fix it.

9Frequently Asked Questions

Q: Why is this undefined in my method callback? A: When a method is passed as a callback, it is later invoked as a plain function, so it loses the object binding. In strict mode that makes this undefined. Wrap the callback in an arrow function or use bind to preserve this.

Q: What is the difference between call and apply? A: Both invoke a function immediately with a this you specify. call takes the arguments listed one by one, while apply takes them as a single array. Otherwise they behave identically.

Q: Do arrow functions have their own this? A: No. Arrow functions have no this of their own and instead use the this of the scope where they were defined. This is what makes them reliable for callbacks inside methods.

Q: Does this work the same inside a class? A: Class methods follow the same rules. Called on an instance, this is the instance; passed as a callback, this can be lost. Binding methods in the constructor or using class fields with arrows are common ways to keep this stable.

📄

Get The Print Version

Download a PDF of this article for offline reading.

About the Publisher

SV

SkillVeris Team

Engineering Team

Our engineering writers turn abstract code concepts into hands-on, project-driven learning experiences.

View all posts

Never miss an update

Get the latest tutorials and guides delivered to your inbox.

No spam. Unsubscribe anytime.

Frequently Asked Questions

21 categories · pick one to explore

Does SkillVeris have a tech blog, and what does it cover?
Yes, the SkillVeris blog has over 500 articles covering AI and machine learning, programming, web development, DevOps, cloud, security, databases and career guidance. Articles are practical and answer-first, and many use the Learn Through Hobbies approach, teaching technical concepts through cricket, music, gaming or cooking analogies. Everything is free to read.
What is the SkillVeris tech glossary and how big is it?
The SkillVeris glossary is a free reference of roughly 2,000-plus technology terms, each with a clear plain-language definition. It spans AI, programming, web, DevOps, cloud, security and database vocabulary, so whenever a lesson, article or job description uses jargon you do not recognise, the glossary gives you a fast, reliable answer.
Are the developer cheat sheets on SkillVeris free to download?
The cheat sheets are completely free to use, like everything else on SkillVeris. Each sheet condenses a language or tool into its essential syntax, commands and patterns for quick reference while coding. They are designed for rapid lookup during real work, complementing the deeper explanations found in study notes and courses.
Which programming references and cheat sheets are available?
Cheat sheets cover the platform's main domains, including programming languages, AI and ML tooling, web development, DevOps, cloud, security and databases, matching the topics of the 37 live courses. Each sheet lists related reading links and hashtags, so you can jump from a quick reference into fuller study notes or blog articles.
How do I find the meaning of a technical term quickly?
Search the SkillVeris glossary, which holds around 2,000-plus terms with concise, plain-language definitions. Each entry gets to the point in its first sentence, then links to related reading like blog posts or study notes for deeper context. It is faster and more consistent than sifting through scattered search results.
Is the SkillVeris blog good for beginners learning to code?
Yes, many blog articles are written specifically for beginners, and the Learn Through Hobbies style makes them unusually approachable: you might learn Python concepts through cricket or understand APIs through cooking. With 500-plus articles across skill levels, beginners can start with fundamentals and keep reading as they advance, entirely free.
Can cheat sheets replace full courses for learning a language?
No, cheat sheets are references, not teaching tools; they assume you already understand the concepts and just need syntax or commands fast. To actually learn a language, take a structured SkillVeris course with its 24–40 lessons and assessments, then keep the cheat sheet beside you while practising in Code Lab.
How often are new blog articles published on SkillVeris?
The blog grows regularly and already exceeds 500 articles, with new posts added as courses launch and technologies evolve. Topics track the platform's catalogue across AI, programming, web development, DevOps, cloud and security, so checking the Blog section periodically surfaces fresh tutorials, explainers and career-focused pieces, all free to read.
Does the glossary cover AI and machine learning terms?
Yes, AI and machine learning vocabulary is a major part of the roughly 2,000-plus term glossary, covering everything from foundational terms to modern concepts around LLMs, RAG and MLOps. Definitions are plain-language and answer-first, which helps when dense AI papers or course lessons throw unfamiliar jargon at you.
Are there cheat sheets for interview preparation?
Cheat sheets work well as interview-day refreshers because they compress syntax, commands and key concepts into scannable references. For dedicated preparation, combine them with the SkillVeris interview questions feature, which includes readiness scoring, plus study notes for depth. Reviewing a relevant cheat sheet just before an interview steadies recall under pressure.
Can I read the tech blog without signing up?
Yes, the blog is freely readable, and SkillVeris never charges for content. All 500-plus articles are open, covering tutorials, concept explainers and career advice. Creating a free account adds value elsewhere on the platform, like course progress tracking and certificates, but reading the blog requires no commitment at all.
How is the SkillVeris glossary different from Wikipedia?
The glossary is purpose-built for learners: definitions are short, plain-language and answer-first, sized for a quick lookup mid-lesson rather than a deep encyclopedic read. Entries also cross-link to related SkillVeris study notes, blog posts and courses, so a definition becomes a doorway into structured learning instead of a dead end.
Do blog articles use the Learn Through Hobbies method?
Many blog articles teach technical topics through hobby analogies, a hallmark of the SkillVeris blog, so you will find articles explaining programming through cricket, machine learning through music, or system design through cooking. The analogy is the teaching device; the article still delivers the real technical concept underneath.
Where can I find quick programming references while coding?
Open the SkillVeris cheat sheets, which are built exactly for that moment: compact, scannable references for syntax, commands and common patterns across languages and tools. Keep the relevant sheet in a browser tab while you work in Code Lab or your own editor, and dip into the glossary for terminology.
Is there a glossary entry for terms I meet in job descriptions?
Very likely yes, with roughly 2,000-plus terms across AI, programming, web, DevOps, cloud, security and databases, the glossary covers most jargon that appears in tech job descriptions. Decoding a listing this way helps you judge role fit honestly and prepares you to discuss those terms in interviews.
Are the blog articles written for the Indian tech audience?
The blog serves Indian learners plus a worldwide audience. Content stays globally relevant while acknowledging realities that matter in India, such as free access being essential for students and freshers, and career guidance that connects naturally to the SkillVeris jobs portal, which aggregates roles across India, UK, USA, Germany and Remote.
Can I suggest a topic for the blog or glossary?
SkillVeris content grows in response to what learners need, so feedback is welcome through the platform's support channels. If a term is missing from the glossary or a topic deserves an article, telling the team helps prioritise it. Meanwhile, the AI Mentor can answer the question immediately, 24/7, at any depth.
Do cheat sheets and glossary entries link to deeper learning?
Yes, every cheat sheet and glossary entry carries related reading links into study notes, blog articles and courses, plus concept hashtags for discovering similar content. This cross-linking means a thirty-second lookup can smoothly become a structured learning session whenever you decide you want more than a quick answer.
What makes SkillVeris programming references trustworthy?
The references are written to strict internal quality standards, kept consistent with the platform's 37 live courses, and never padded with invented statistics or hype. Definitions and cheat sheets are reviewed against the same content contracts that govern courses, and the answer-first style makes any inaccuracy easy to spot and correct.
How do the blog, glossary and cheat sheets fit into my learning routine?
Use them as satellites around your main course: read blog articles for context and motivation, hit the glossary the instant jargon appears, and keep cheat sheets open while coding. Together with study notes, Code Lab and the 24/7 AI Mentor, they turn passive reading into a complete, free learning system.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse