0% found this document useful (0 votes)
73 views2 pages

Functions and Classes

The document explains the concepts of functions and classes in JavaScript, highlighting their importance in creating reusable code. It provides syntax examples for defining functions and classes, including a specific function for calculating the area of a square and a class for a student with attributes and methods. This structured approach aids in organizing and managing complex applications effectively.

Uploaded by

sheikhshahib123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
73 views2 pages

Functions and Classes

The document explains the concepts of functions and classes in JavaScript, highlighting their importance in creating reusable code. It provides syntax examples for defining functions and classes, including a specific function for calculating the area of a square and a class for a student with attributes and methods. This structured approach aids in organizing and managing complex applications effectively.

Uploaded by

sheikhshahib123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Functions/ Methods and Classes

in Web Technology

Method/Function:
In JavaScript, functions and methods are fundamental building blocks for creating reusable
code.
Syntax in javascript:
function name(params) {

Example: Function for the calculation of Area of Square


function Area(){
let Length=10;
let Width=10;
const Result = Length*Width;
console.log('Area of Square:' +Result)
}

Classes:
In JavaScript, classes are a blueprint for creating objects. They encapsulate data (properties)
and behavior (methods) into a single unit. Classes provide a structured way to organize and
reuse code, making it easier to create complex applications.
Syntax:
class name {
constructor(parameters) {

}
}

Example: Class of a student


 Class will have constructor
 It will have some attributes
 It will have some methods/functions: functions within class should be written without
function keyword.

class Student {
constructor(Id, Roll_no, Class, Section) {
this.Id=Id;
this.Roll_no=Roll_no
this.Class=Class
this.Section=Section
}

examMarks() {
let Eng=100;
let Urdu=100;
const total=Eng+Urdu;
console.log('Total Marks:'+total)
}
}

You might also like