0% found this document useful (0 votes)
14 views

Basic

The document covers various JavaScript concepts including variable declarations using 'let' and 'const', data types (primitive and non-primitive), strict mode, operations, memory management, string manipulation, and math functions. It highlights best practices and common pitfalls in JavaScript coding. Additionally, it provides examples and explanations for each concept to aid understanding.

Uploaded by

anuraggupta2004a
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)
14 views

Basic

The document covers various JavaScript concepts including variable declarations using 'let' and 'const', data types (primitive and non-primitive), strict mode, operations, memory management, string manipulation, and math functions. It highlights best practices and common pitfalls in JavaScript coding. Additionally, it provides examples and explanations for each concept to aid understanding.

Uploaded by

anuraggupta2004a
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/ 30

01_basic syntax var let and const\basic.

js

1 console.log("js by chain aur code...")


2
3 // var a = 45
4 // but in new js version we dont use this keyword 'var' becuase of its scope
acces problem
5 // ex
6
7 let Myname = "Anurag"; //string
8 console.log(Myname);
9
10 let age = 20 ; //number
11 console.log(age);
12
13 let isRaining = true; //boolean
14 console.log(isRaining);
15
16 const PI_value = 3.142;
17 console.log(PI_value);
18
19 myName2 = "lala"; //this is also valid but not good practise as programmer
20 // this also look like u assign the new value in this variable
21 console.log(myName2);
22
23 let value; //just initilize the variable but not assign the value i.e.
undefined
24 console.log(value);
25
26 // printing the all variables in table for
27 console.table([Myname,age,isRaining,PI_value,myName2,value])
28
29 {
30 // console.log(x); // undefined (due to hoisting)
31 let x = 10;
32 console.log(x); // 10
33 }
34 console.log(x);
02_Data_Types (Primitive and Non-Primitive)\dataType.js

1 // waise to maine already ise 01 me cover kr liya tha ok


2
3 let myName = "Anurag";
4 console.log(typeof myName);
5
6 let age = 20
7 console.log(age);
8
9 let isCodeWorking = true
10 console.log(isCodeWorking);
11
12 let futureGoal; //means kuch to hoga but abhi pta nai hai
13 console.log(futureGoal);
14
15 let temperatur = null //null is stand alone value means kuch bhi nai
khaali ek dum 'nothing' or 'no-value'
16 console.log(typeof temperatur);
17 // This shows object data types due to a historical bug in JavaScript.
The typeof operator mistakenly treats null as an object.
18
19 // other remaining data type is symbol , BigInit --> this both rarely
use ok so we have total 7 data types which known as Primitive data Type
20 let id = Symbol("17");
21 let bigNumber = 56446546446546464646­
46n;
22
23
24 // 2. Reference or Non - Primitive data Types ----> Array , Object ,
Functions
25
26 let arr = ["anurag",17,"Lala",20];console.log(arr,typeof arr);
27 let obj = {myName:"Anurag",age:20} ; console.log(obj , typeof obj
,Array.isArray(arr));
28 function funcName(){console.log(" i am a function");} ; funcName() ;
console.log(typeof funcName);
29
02_Data_Types (Primitive and Non-Primitive)\diiff_primitive_Non-
premitive.js

1
2
3 /*
4 1. Primitive data types:
5 Copy by Value: When assigning a primitive type (like number,
string, boolean), a new copy of the value is created. Changes to the
copy do not affect the original value.
6 Ex: below
7 */
8 let myName = "Anurag Gupta"; console.log(myName);
9
10 let myName2 = myName ; console.log(myName2);
11
12 myName2 = "Lala gupta"; console.log(myName2);
13
14 console.log(myName); //see the actual value is not changed
15
16
17 /*
18 2. Non-primitive or By Reference:
19 Copy by Reference: When assigning a non-primitive type (like object,
array), a reference to the same memory location is used. Changes to the
reference affect the original object.
20 Ex : given below
21 */
22
23
24 let obj1 = {myName : "Anurag",age : 20, yearOfClg : "3rd"}
25 console.log(obj1);
26
27 let obj2 = obj1
28 console.log(obj2);
29
30 obj2.myName = "lala"; console.log(obj2);
31 console.log(obj1); //assign the value in obj2 also reflected in obj1
32
33 obj1.age = 21; console.log(obj1);
34 console.log(obj2);
02.1_imp_ use strict mode in js\strict.js

1 /*
2 "use strict"; is a directive that activates strict mode in JavaScript
or newer version of js, enforcing stricter rules for better code
quality.
3
4 Benefits
5 Catches Errors: Throws errors for common mistakes.
6 Disables Unsafe Features: Prevents use of certain features that are
error-prone.
7 */
8
9 // Non-strict mode (No "use strict";)
10 x = 10; // No error, `x` is created as a global variable
11 console.log(x); // 10
12
13
14 // Strict mode (with "use strict";)
15 "use strict";
16
17 try {
18 x = 10; // Error: `x` is not declared, will throw a ReferenceError
19 } catch (e) {
20 console.error(e); // ReferenceError: x is not defined
21 }
22
23 // Correct way to declare a variable in strict mode
24 "use strict";
25 let x = 10; // No error, `x` is properly declared using `let`
26 console.log(x); // 10
03_ diiferent types of operations\opration.js

1 // i skip this because i know the diff operations of js or lknow from


other language
2 // but some confusing opreation or calculatuion in js ab use bug bolo
ya languag ka khaami bolo ya features
3
4 console.log(1 + 2);
5 console.log(1 + "2");
6 console.log("1" + 2);
7 console.log("1" + 2 + 2 );
8 console.log(2 + 2 + "1" );
9 console.log(4 + 5 * 9 % 3); //bad practise😞
10 // but this is only for knowledge pupose or exam pupose
11 // actuall me yeah bhot wrong practise hai aise confusing operation use
krna
12 console.log(4 + (5*( 9 % 3))); //good practise😊
13
14 console.log(+""); // "" means false
15 console.log(+true); //true means 1
16
17
18 /*
19 1. Arithmetic Operations:
20 Addition: +
21 Subtraction: -
22 Multiplication: *
23 Division: /
24 Modulus: %
25 Exponentiation: **
26
27 2. Comparison Operations:
28 Equal to: ==
29 Strict equal to: ===
30 Not equal to: !=
31 Strict not equal to: !==
32 Greater than: >
33 Less than: <
34 Greater than or equal to: >=
35 Less than or equal to: <=
36
37
38 3. Logical Operations:
39 AND: &&
40 OR: ||
41 NOT: !
42
43
44 4. Assignment Operations:
45 Assign: =
46 Add and assign: +=
47 Subtract and assign: -=
48 Multiply and assign: *=
49 Divide and assign: /=
50 Modulus and assign: %=
51
52 5. Unary Operations:
53 Unary plus: +
54 Unary minus: -
55 Increment: ++
56 Decrement: --
57 Not: !
58
59 6. String Operations:
60 Concatenation: + (combining strings)
61
62 7. Bitwise Operations
63 AND: &
64 OR: |
65 XOR: ^
66 NOT: ~
67 Left shift: <<
68 Right shift: >>
69 Unsigned right shift: >>>
70
71 8. Type Conversion Operations
72 To string: String()
73 To number: Number()
74 To boolean: Boolean()
75 */
04_Stack and Heap Memory\memory.js

1 // 1. Stack: Fast, temporary storage for (Primitive Data Type) small,


simple data and function calls.
2 let myName1 = "Anurag" ;console.log(myName1);
3
4 let myName2 = myName1; console.log(myName2);
5
6 myName2 = "Lala"; console.log(myName2);
7
8 console.log(myName1);//see the og value not changed only just copied
value pass to the 'myName2' var
9
10
11
12
13 // 2. Heap: Slower, flexible storage for (Non-Premitive Data Type)
larger and more complex data structures.
14
15 let obj1 = {myName : "Anurag", age : 20}; console.log(obj1);
16
17 let obj2 = obj1 ; console.log(obj2);
18
19 obj2.age = 21 ; console.log(obj2);
20
21 console.log(obj1);//see the both variable obj changed because both
variable accessing obj reference
22
23
24 // some confusion is in function that exactly function kha jata hai
heap ya stack me jata
25
26
27 function greet(){
28 console.log("hello dear")
29 }
30 greet()//this is actual function so it will store in heap memory
31
32 let greet2 = greet // so reference to 'greet()' assigned to the
'greet2()' var, so this will store in Stack
33 greet2()
34
05_strings concept\string.js

1
2 // In JavaScript, a string is a sequence of characters used to
represent text, enclosed in single quotes ('), double quotes ("), or
backticks (`) for template literals. Strings are immutable and can be
manipulated using various built-in methods
3
4 let myName = "Anurag"
5 let age = 20;
6
7 // traditional method to print the string
8 console.log("My name is " + myName + " and age is " + age + " ok");
//no recommed to use this way
9
10 // modern way to print string and known as string interpolation
11 console.log(`my name is ${myName} and age is ${age} ok`); //recomended
to use this way
12
13 // another way to initialize the string using String class
14 let obj = new String("Anurag");
15
16 console.log(obj, obj.length , obj[0])
17
05_strings concept\strings_methods.js

1 let myName = "Anurag Gupta";


2
3 // 1. Get the length of the string
4 console.log(myName.length);
5
6 // 2. Convert the string to lowercase
7 console.log(myName.toLowerCase());
8
9 // 3. Convert the string to uppercase
10 console.log(myName.toUpperCase());
11
12 // 4. Replace from present value ('Anurag') to Replace value ('Lala')
in the string
13 console.log(myName.replace("Anurag", "Lala"));
14
15 // 5. Get the character through index position
16 console.log(myName.charAt(3));
17
18 // 6. Find the index of string just giving the char value
19 console.log(myName.indexOf("G"));
20
21 // 7. Check if the string starts with given str or char
22 console.log(myName.startsWith("Anu"));
23
24 // 8. Check if the string ends with given str or char
25 console.log(myName.endsWith("mta"));
26
27 // 9. `includes(substring)` - Check if the string contains a substring
28 console.log(myName.includes("lala"));
29
30 // 10. `split(separator)` - Split the string into an array of
substrings
31 console.log(myName.split(" "));
32
33 // 11. `concat(string2, string3, ...)` - Concatenate multiple strings
34 console.log(myName.concat(" - i am added through concatination ","-
>another one"));
35
36 // 12. slice(start, end): Extracts a substring from start to end (end
not included). Supports negative indices.
37 console.log(myName.slice(0,6));
38 console.log(myName.slice(-4,-1));
39
40 // 13. substring(start, end): Extracts a substring from start to end
(end not included). Does not support negative indices, if given the
it's treat as 0
41 console.log(myName.substring(0,8));
42 console.log(myName.substring(-5,8)); //so here -5 treat as 0
43
44 // 14. `trim()` - Remove whitespace from both ends of the string
45 myName2 = " lala Gupta "
46 console.log(myName2);
47 console.log(myName2.trim());
48
49
Math-Number-Date.js

1 // date
2 let date = new Date()
3
4 console.log(date);
5 console.log(date.toString());
6 console.log(date.toISOString());
7 console.log(date.toUTCString());
8 console.log(date.toLocaleTimeString());
9 console.log(date.getFullYear());
10 console.log(date.getMonth());
11 console.log(date.getDate());
12 console.log(date.getDay());
13 console.log(date.getHours());
14
15
16 const newDate = new Date(2023,8,5)
17 console.log(newDate.toString());
18
19 // maths and math random number
20
21
22 console.log(Math);
23
24 // mostly used is random() always betwwen 0 to 1j
25 console.log(Math.random());
26
27
28 // 1. Rounds a number up to the nearest integer
29 console.log(Math.ceil(4.5));
30
31 // 2. Rounds a number down to the nearest integer
32 console.log(Math.floor(4.5));
33
34 // 3. Rounds a number to the nearest integer; 4.4 to 4, 4.5 to 5
35 console.log(Math.round(4.4), Math.round(4.5));
36
37 // 4. Returns the largest number from a set of values
38 console.log(Math.max(4, 5, 8, 6, 7, 10));
39
40 // 5. Returns the smallest number from a set of values
41 console.log(Math.min(4, 5, 8, 6, 7, 10));
42
43 // 6. Returns the absolute value (magnitude) of a number
44 console.log(Math.abs(-10), Math.abs(10));
45
46 // 7. The value of π (pi), approximately 3.14159
47 console.log(Math.PI);
48
49 // 8. Returns the square root of a number
50 console.log(Math.sqrt(81));
51
52 // mainly we use this random method to guess the number between max or
min number like 10 or 20 ke bich me choose kro
53
54 // trick to do as we know radom gives only val between 0 to 1
55
56 let minNum = 10;
57 let maxNum = 20
58
59 let generated_num_logic = Math.random() * (maxNum - minNum + 1) +
minNum; console.log(generated_num_logic);
60
61 let actual_generated_num­= Math.floor(generated_num_logic)
62 console.log(actual_generated_num­
);
63
64
65 // number in js
66
67 // dynamic declaration
68 let score = 787;
69 console.log(score , typeof score);
70
71
72 // but we can mannualy or hardcore the number through number class
73
74 let score2 = new Number(1234)
75 console.log(score2 , typeof score2);
76
77
78 // some Number class methods
79
80 let numberVal = 454.5685
81
82 console.log(numberVal.toFixed(2));
83
07_Arrays and its methods\1_Array.js

1 //Always remember except primitive data type everything is an object


2
3 let arr = [4,"lala",35,"Anurag",81,9,]
4 console.log(arr, typeof arr);
5 console.log(arr[2]);
6
7
8 const arr2 = new Array(1,2,85,69)
9 console.log(arr2, typeof arr2);
10 // this why its data types is object becuase it store in obj fromat
behind the seen for better understanding use console in browser
11 /*
12 (4) [1, 2, 85, 69]
13 0 : 1
14 1 : 2
15 2 : 85
16 3 : 69
17 length : 4 */
18
19 console.log(Array.isArray(arr2));//to check the arr
20
21 // Array.from(): Creates a new array from an array-like or iterable
object.
22 console.log(Array.from(["Anurag",54,"sameer",78]));
23
24 // Array.of() creates a new array where each argument provided becomes
an element in the new array.
25 console.log(Array.of(100,45,65));
26
27
28 let arr3 = [12,"lala","ronit",45,78]
29
30
31
32
33
34
35
36
37
38
39
07_Arrays and its methods\2_Array_methods.js

1 // In JavaScript, an array is an ordered collection of values, where


each value is identified by a numeric index, starting from 0. Arrays
can store elements of any type and support various methods for
manipulating and accessing these elements.
2
3
4
5 // An array is a special type of object that holds a list of values.
6 let arr = [45,78,"Anurag",19,"lala"]
7 console.log(arr);
8
9 console.log(arr.indexOf("Anurag"));//basic methods for finde the index
by giving value of array
10 console.log(arr.length);//return lenght of arr
11
12
13
14 // 1. push() - Adds one or more elements to the end.
15 arr.push(20,"raju");
16 console.log(arr);
17
18 // 2. pop() - Removes the last element
19 arr.pop();console.log(arr);
20
21 // 3. unshift() - Adds one or more elements to the Starting of the
array
22 arr.unshift("addInSt","moreValInSt",91);console.log(arr);
23
24 // 4. shift() - Removes the first element from the array
25 arr.shift();console.log(arr);
26
27
28
07_Arrays and its methods\3_more_methods.js

1 // 5. slice() - Returns a new array containing a portion of the


original array and last or end index not included
2 let newArr = arr.slice(1,4)
3 console.log(newArr);
4
5 //(this is bite confusing so i am taking new arr for this example)
6 // 6.splice():Adds or removes elements from an array at specific index,
modifying the original array.
7
8 let fruits = ["apple", "banana", "cherry", "orange","carrot"];
9
10 //fruits.splice(1, 3);//*removing element* from index 1 to 3 i.e.
banana, cherry and orange so kya bacha humare pass apple or carrot
11 console.log(fruits);
12
13 // 7. concat(): is used to merge two or more arrays into a new array
without changing the original arrays.
14 let array1 = [1, 2, 3];
15 let array2 = [4, 5, 6];
16 let combined_arr = array1.concat(array2);
17 console.log(combined_arr);
18
19
20 /**imporatant confusio
21 slice(): Creates a new array from a part of the original.
22 splice(): Changes the original array by adding or removing elements**/
23
24 /*SOME MORE ADVANCE METHODS OF ARRAY ALSO LIKE ]
25 spread operator[...] : is used to expand elements from an array or
object into individual elements. It simplifies copying, combining, and
manipulating arrays or objects.
26 forEach(): Perform an action on each item.
27 map(): Make a new array with modified items.
28 filter(): Make a new array with only the items that meet a
condition.
29 reduce(): Combine all items into one value.
30 */
08_Objects and its methods\1_objects.js

1 /* Object:
2 A collection of key-value pairs where each key (also called a
property) is a string, and each value can be any data type, including
other objects or functions.
3
4 **TWO WAYS TO REPERSNT OBJECTS:**
5 1. Singleton object:
6 - it created using Object constructor
7
8 2. Object Literal:
9 - A simple way to create objects using curly braces {} with
key-value pairs.
10
11 */
12
13 const rollNo = Symbol('rollNo'); // Create a unique symbol
14
15 let obj = {
16 myName : "Anurag", //behind the scene the key also get converted
in this "myName" i.e. in double cotts
17 age : 20,
18 colorTone : "kaala hai",
19 MyFunc : function(){console.log("calling from the object");},
20 // here how to use symbol as a property key in obj
21 [rollNo] : 17,
22 // how to use object key as variable using 'this' keyword
23 greetFunc : function(){console.log(`namaste ${this.myName}`);}
//here this refer to obj i.e. object
24 }
25
26 console.log(obj);
27 // console.table(obj)
28
29 // accessing the value using dot
30 console.log(obj.age,obj.colorTone,typeof obj);
31
32 //another way to acces the objec value using keys with square double
quotes
33 console.log(obj["age"],obj["colorTone"],typeof obj);
34
35 console.log(obj[rollNo], typeof rollNo);
36 obj.MyFunc()
37 obj.greetFunc()
38
39 // HOW TO CHANGE THE VALUE OF KEYS
40
41 obj.myName = "Anurag Gupta"
42 console.log(obj);
43
44
45
08_Objects and its methods\2_objects_Methods.js

1
2 // creating object using Object class
3 let insta_obj = new Object()
4 console.log(insta_obj);
5
6 // Adding elements in the object
7
8 insta_obj.id = 111533
9 insta_obj.user_name = "anurag_2004"
10 insta_obj.isLoggedIn = true
11 insta_obj.isStatusUpdate = false
12
13 console.log(insta_obj);
14
15 //SOME object class METHODS OR OPERATIONS
16
17 console.log(Object.keys(insta_obj));// Listing all property or keys
names
18 console.log(Object.values(insta_obj));// Listing all property values
19 console.log(Object.entries(insta_obj));// Listing all key-value pairs
in an array form
20
21
22 let person1 = {
23 ogName : "Anurag",
24 RollNo : 17
25 }
26
27 let person2 = {nickname : "lala",age : 20}
28
29 // combine the two or more object using Object class assign method in
an single obj
30 let combindePersonDet = Object.assign(person1,person2)
31 console.log(combindePersonDet);
32
33 console.log(person1.hasOwnProperty("RollNo"));
34
35
36 // another general way to combine the 2 or more object using spread
oprator
37 let combindePersonDet_sp­
eradOperator = {...person1,...person2}
38 console.log(combindePersonDet_sp­
eradOperator);
39
40
08_Objects and its methods\3_object_destructing.js

1
2
3 let obj = {myName : "Anurag",rollNo:17,isInClg : false}
4 console.log(obj);
5
6
7 // accessing one key's value from an objec
8 console.log(obj.myName,obj.rollNo);
9
10 // another way to accessing the key's value using object destructuring
11
12 let {myName,rollNo} = obj;
13 console.log(myName,rollNo);
14
15 // we can give a shortcut name for accessing the key like alias means
short form like "i dont know" : idk(shortcut or alias)
16 let {myName:nam , rollNo : id} = obj
17 console.log(nam , id);
18
19
20
09_function and Types of function\1_function.js

1 /*
2 A function in JavaScript is a reusable piece of code that performs
a specific task or calculates a value. You define a function once and
can call or invoke it multiple times throughout your code.
3
4 syntax :
5 function function_name(){
6 // code
7 }
8
9 🔴 Use 'return' when you need to send a result from a function
and use that result elsewhere in your code.
10 Use 'console.log' to output information to the console for
debugging or checking values. 🔴
11 */
12
13 // keyword func_name ()indicate func {}scope of function
14 function greet () {
15 console.log("My");
16 console.log("Name");
17 console.log("is");
18 console.log("Anurag");
19 };
20 greet()
21
22 // some basic types of function
23
24 // anymous function--> useed in object example
25 let obj= {
26 myName : "Anurag",
27 namaste : function(){console.log("Namaste",this.myName); }
28 };
29 obj.namaste();
30
31 // arrow function : explicit means here we use the return
32 const func_name2=()=>{return `I am arrow function`}
33 console.log(func_name2());
34
35 // Arrow function : Implicit means here we not use return statment
36 const func_name2_I = ()=> `i am arrow function`;
37 console.log(func_name2_I());
38
39
40
41
42 // IIFE (Immediately Invoked Function Expression:
43 // A function that is defined and executed immediately.
It is used to create a new scope and prevent variable leaks into the
global scope
44
45 (function() {
46 // code to execute immediately
47 console.log('I am an IIFE!');
48 })();
49
50 // parameter in IIFE
51
52 ((name)=>{console.log(`my name is ${name}`);})("Lala");
53
54 /*
55 create process
56 (in firt braces function will declare)(); //AND SET YOUR IIFE DONE😀
57 */
09_function and Types of function\2_more_types_basedOnParameter.js

1 /*
2 syntax:
3 **declaring function**
4 function func_name (parameter){
5 \\codes or logic
6 };
7
8 **calling the function**
9 func_name(argument);
10
11 📝
12 Parameter: Function ke definition mein likha gaya variable.
13 Example: function add(x, y) {} (x aur y parameters hain)
14
15 Argument: Function call karte waqt di gayi actual value.
16 Example: add(2, 3); (2 aur 3 arguments hain)
17 📝
18
19 */
20
21
22 function addNum(num1,num2){
23 console.log(num1 + num2);
24 }
25
26 addNum(45,10);
27 // Type Coercion in JavaScript is the automatic conversion of values
from one type to another Data type, such as converting a number to a
string or vice versa, to perform operations like addition.
28 addNum(45,"40");addNum("a",65)
29
30
31 // Default parameter - ye hum tab use krte hai jab hume parametr ki
value empty or undefined nai chaiye hoti hai
32
33 function greet(name="Dear"){
34 console.log(`Hello ${name}😊`);
35 }
36 greet()
37
38 // handle the parameter in this case we dont want any default value we
need actual argument, otherwise send msg enter the name or custom error
msg so let see
39
40 function greet2(name){
41 if(name===undefined){
42 // console.log("mai return ke uper likha hu to mai chalunga");
43 return `plz pass ur name in greet2`
44 }
45 else{
46 // console.log("mai return ke uper likha hu to mai chalunga");
47 return `Hello ${name}`
48 console.log("always remeber reurn ke bad ka koi code run nai
hota hai");
49 }
50 }
51
52 console.log(greet2());
53 console.log(greet2("Anurag"));
54
55
56 /*
57 Rest Operator (...): Used in function parameters to collect multiple
arguments into an array
58 Spread Operator (...): Used to expand an array or object into
individual elements.(we already familiar with this spread opertot)
59 **************** BOTH ARE SAME BUT USE CASES ARE DIFFERENT ONLY
**************************
60
61 Kabhi kabhi humare pass aisi conditon aa jati hai jaha pr
hum exact kitne parameter pass honge function pta nai hota to aise
62 situations ko handle krne ke liye hum spread operator[...]
63
64 jaise grocery shop hai wah per fruits hai to hume exact nai
pta customer kitne fruits lega
65
66 */
67
68 function allFruits(...nameOfFruits){
69 console.log(`Name of fruits : ${nameOfFruits}`);
70 console.log(`Total Fruits : ${nameOfFruits.length}`);
71
72 }
73
74 allFruits("apple","kele","Aaam😋","orange")
75
09_function and Types of
function\3_how_to_use_object_and_array_in_function.js

1
2
3 // 1. USING OBJECT IN FUNCTION
4 const personObj = {
5 name: "Anurag",
6 age: 20
7 };
8
9 //pta hai function ka nam odd but understanding
10 function use_of_obj_in_func(anyObject) {
11 console.log(`my name is ${anyObject.name} and age is
${anyObject.age} years old.`);
12 console.log(anyObject);
13 }
14
15 use_of_obj_in_func(personObj)
16
17 // also we can pass direct object {} in argument
18 use_of_obj_in_func({name:"bacha hu",age:4,newAdd : "bus dekhne ke liye
add kiya hu 😁"})
19
20
21
22 // 2. USING ARRAY IN FUNCTION
23
24 function use_of_arr_in_func(anyArray){
25 console.log(anyArray);
26 console.log(`printing the 1st value (i.e. index[0]) of array :
${anyArray[0]}`);
27 console.log(`Length of given array is ${anyArray.length}`);
28 }
29
30 let fruitsArr = ["Apple","orange","banana","cherry"]
31
32 use_of_arr_in_func(fruitsArr);
33
34 // also we can array manually in function
35 use_of_arr_in_func([17,445,987,54,35,10]);
09_function and Types of function\4_Implicit_and_Explicit_return.js

1
2 /*
3 1. Block Body Arrow Function: [also know as Explicit return]
4 Terminology: "Block body" or "Block syntax"
5 Description: Uses curly braces {} and requires an explicit return
statement.
6 */
7
8 let block_body = () => {return `kuch nai`};
9 console.log(block_body());
10
11 /*
12 2. Concise Body Arrow Function: [also know as Implicit return]
13 Terminology: "Concise body" or "Expression body"
14 Description: Directly returns the value without curly braces or
return keyword. but you can use braces for better readablity '()'
15 */
16
17 // let concise_body = () => `kuch nai`;
18 let concise_body = () => (`kuch nai`);
19 console.log(concise_body());
20
21 // this is use in mostly higher order functions like map, filter and
reduce

You might also like