जावास्क्रिप्ट में कार्य और विधियाँ समान हैं, लेकिन विधि एक फ़ंक्शन है, जो किसी वस्तु का गुण है।
जावास्क्रिप्ट में फ़ंक्शन का एक उदाहरण निम्नलिखित है -
function functionname(param1, param2){
// code
} उदाहरण
विधि किसी ऑब्जेक्ट से संबद्ध एक फ़ंक्शन है। जावास्क्रिप्ट में एक विधि का उदाहरण निम्नलिखित है -
<html>
<head>
<script>
var employee = {
empname: "David",
department : "Finance",
id : 002,
details : function() {
return this.empname + " with Department " + this.department;
}
};
document.write(employee.details());
</script>
</head>
</html> आउटपुट
