What is this keyword in javascript?
Abu Jaid
Posted on August 19, 2022
The this
keyword is probably one of the odder ducks you’ll encounter while trying to learn JavaScript. What it does, in essence, is standing in for the current object that has focus relative to the handler. Here’s an example like the one discussed in the previous section.
<form name="myForm">
<input type="text" name="phoneNumber" onchange="checkPhone
(this.value)" />
</form>
this is used to suggest “this input element,” and value is a property that stores the value associated with this form element. You could also access that same value as the following in order to pass along the value.
<form name="myForm">
<input type="text" name="phoneNumber" onchange="checkPhone (document.myForm.phoneNumber
The this Keyword.value)" />
</form>
Note that the name of the form and the name of the element are both vital in getting at the correct value. That’s one reason for the this keyword; another is simple convenience
Posted on August 19, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
November 30, 2024