Constructor Function:
◾Constructor function is used to create and initialize multiple objects of the same type.
◾It overcomes the difficulty of multiline code, construct a single line.
◾Constructor must be called with the newoperator.
Const phone1 ={
brand:"Nothing",
model:"cmf phone 2pro",
price:20000
}
Const phone2 = {
brand:"Realme",
model:"P4 pro",
price:22000
}
✓ It's a normal object creation for phone details.
✓ This method enough with two or three phone details.
✓ What if, can write the details of all realme brand mobiles,so overcome this difficult use a contructor function to construct a code in single line.
Example:
EXPLANATION:
🔹Create a function to give the parameters(Nothing","cmf phone 2pro",20000) of you write.
🔹Then to sets a this operation to call a properties and methods.
🔹This multiline code
brand:"Nothing",
model:"cmf phone 2pro",
price:20000
Written a single line code of
const phone 1 = new phone("nothing", "cmf phone 2pro", 20000);
🔹Writing, const phone2 = new phone("realme", "p4 pro" 22000);
instead of this code
brand:"Realme",
model:"P4 pro",
price:22000
🔹Use the newkeyword,when you use the new keyword javascript performs the above steps.
🔹Use the this to Print the code like (this.brand, this.model, this .price);
OUTPUT:
Return Statement in Javascript:
◾The return statement is used to end function execution and a value to be sent back to the caller.
◾The caller used that value at any time.
◾If the caller don't return the value the value won't used to be any variable.
EXAMPLE:
🔹Create a function named add(a,b)
🔹Return the parameters a and b.
🔹Create a new variable to store the function name and give the values of parameters.
🔹Then print the code.
🔹The sum output 15 is return to the caller function add.
🔹The value can be used at any variable,if not the give the return statement the value won't be used at any variable.
Returning value of some data types:
Undefined:
Returned for variables declared but not yet assigned a value.
Boolean:
Returned for true and false.
Number:
Returned integers(1,2,3), floats(3.1,2.13), and special values like NaN and Infinity.
BigInt:
Used for larger integers like 123456.
String:Returned for all textual data with a double quotation like ("javascript","Deva","123")
Object:Returned for objects {} and arrays [].
Basic Array Methods:
Array length
Array isArray)
Array toString()
Array delete()
Array at()
Array concat()
Array Join()
Array copy Within()
Array pop()
Array flat()
Array push()
Array slice()
Array shift()
Array splice()
Array unshift()
Array to Spliced()
(To be discussed )




Top comments (0)