JavaScript Methods
JavaScript Methods
Example
const person = {
firstName: "John",
lastName: "Doe",
id: 5566,
fullName: function() {
}
};
Try it Yourself »
What is this?
In JavaScript, the this keyword refers to an object.
D k d
In a function, this refers to the global object.
Dark code
HTML CSS JAVASCRIPT
In a function, in strict mode, this is undefined .
Note
this is not a variable. It is a keyword. You cannot change the value of this .
See Also:
The JavaScript this Tutorial
JavaScript Methods
JavaScript methods are actions that can be performed on objects.
Property Value
firstName John
lastName Doe
age 50
eyeColor blue
D k d
You access an object method with the following syntax:
Dark code
HTML CSS JAVASCRIPT
objectName.methodName()
You will typically describe fullName() as a method of the person object, and fullName as a
property.
The fullName property will execute (as a function) when it is invoked with ().
Example
name = person.fullName();
Try it Yourself »
If you access the fullName property, without (), it will return the function definition:
Example
name = person.fullName;
Try it Yourself »
Example
person.name = function () {
};
Dark mode
D k d
Dark code
Try
it Yourself
HTML » CSS JAVASCRIPT
let x = message.toUpperCase();
HELLO WORLD!
Example
person.name = function () {
};
Try it Yourself »
❮ Previous Next ❯
NEW
We just launched
W3Schools videos
Dark mode
D k d
Dark code
HTML CSS JAVASCRIPT
Explore now
COLOR PICKER
Get certified
by completing
a JavaScript
course today!
school
w3 s
2
CE
02
TI 2
R
FI .
ED
Get started
CODE GAME
Dark mode
D k d
Dark code
HTML CSS JAVASCRIPT
Play Game
Report Error
Spaces
Pro
Get Certified
Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
W3.CSS Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial
Top References
HTML Reference
CSS Reference
JavaScript Reference
SQL Reference
Python Reference
W3.CSS Reference
Dark mode
Bootstrap Reference
D k d
PHP Reference
Dark code
HTML CSS JAVASCRIPTHTML Colors
Java Reference
Angular Reference
jQuery Reference
Top Examples
HTML Examples
CSS Examples
JavaScript Examples
How To Examples
SQL Examples
Python Examples
W3.CSS Examples
Bootstrap Examples
PHP Examples
Java Examples
XML Examples
jQuery Examples
Get Certified
HTML Certificate
CSS Certificate
JavaScript Certificate
SQL Certificate
Python Certificate
PHP Certificate
jQuery Certificate
Java Certificate
C++ Certificate
C# Certificate
XML Certificate
FORUM |
ABOUT
W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of
all content.
While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.