Java functions
Java functions
1.FUNCTION:A set of statements that performs a task or caluculates a value but for
a procedure to qualify as function.
function name(){
let a="vali"
let b="sahab"
let c="yasaswi"
console.log(a,b,c)
}
name()
function add(a,b,c){
console.log(a,b,c)
}
add("dell","hp","lenovo")
2.RETURN FUNCTION:A return is a value that a function returns to the calling script
or function when it completes its task. A return value can be any one of the four
variable types: handle, integer, object, or string.
3.DATA TYPES:A data type is an attribute associated with a piece of data that tells
a computer system how to interpret its value.
//String :
a.var str1="hi world"
var str2="hello world"
console.log("str1","str2")
//Integer :
b.var num1=5
var num2=8
console.log(num1+num2)
//Boolean :The boolean (not Boolean) is a primitive data type in JavaScript. It can
have only two values: true or false. It is useful in controlling program flow using
conditional statements like if else, switch, while loop, etc.
c.var a=true
var b=false
console.log(a,b)
//Undefined :
d.var a= undefined
var b= undefined
console.log(b,a)
//Null :In JavaScript, null is a special value that represents an empty or unknown
value. For example, let number = null; The code above suggests that the number
variable is empty at the moment and may have a value later.
e.var a= null
var b= null
console.log(b,a)
4.Array:In JavaScript, an array is one of the most commonly used data types. It
stores multiple values and elements in one variable. These values can be of any
data type — meaning you can store a string, number, boolean, and other data types
in one variable.
*var arr=[54,64,74,84,94]
console.log(arr)
output:[54,64,74,84,94]
*var add=["yash",50,"vali",60,"shaik"]
console.log(add)
*var add=["yash",50,"vali",60,"shaik"]
console.log(add.length)
var add=["yash",5,"shahab",4,"valli",9,6]
console.log(add)
add.pop();
console.log(add)
output:4
[ 'Sony', 'Lg', 'Bpl' ]
output:9
[
'Philips', 1,
'Haier', 2,
6, 8,
'Sony', 7,
'Lg', 5,
'Bpl'
]
output:length of array 9
length of the array 10
[
'Realme', 'Haier',
2, 6,
8, 'Sony',
7, 'Lg',
5, 'Bpl'
]
5.operaters :
// arthematic operaters :Arithmetic operators are the fundamental mathematical
operators used in programming to carry out calculations on numerical data. In
JavaScript, arithmetic operators can be utilized to perform addition, subtraction,
multiplication, division, and modulo operations.
var a=40
var b=30
console.log("The value of a+b is",a+b)
var x=80
var y=20
console.log("The value of x-y is",x-y)
console.log("Tha value of x*y is",x*y)
console.log("The value of x/y is",x/y)
var b = 10;
b += 2;
console.log(b)
output:12
// comparrision operater :The "===" operator compares the variable's value and data
types. It will return true if the value and data type are the same. For example, if
we compare a===3 and a==="3", then in the first case, it will return true if the
assigned value of a is 3, and in the second case, it will return false.
var x=50
var y=500
console.log(x==y)
console.log(x>y)
console.log(x<y)
// logical & operater :The logical AND operator ( && ) returns true if both
operands are true and returns false otherwise.
// logical NOT operater :The logical NOT operator flips the value of a boolean. If
the value is true, the NOT operator returns false. If the value is false, the NOT
operator returns true.
console.log(!false)
console.log(!true)
6.Condition
*If statement :The IF statement works by checking the expression to see whether a
condition is met and returns a value based on the output obtained.
var age=25;
if (age>=18){
console.log("yasaswi adultperson")
}
*else If :"else if" is a conditional statement that allows you to specify multiple
conditions to be evaluated in a sequence.
//For loop:A "For" Loop is used to repeat a specific block of code a known number
of times.
//While loop:A while loop is a loop that continues to run and execute a while
statement as long as a predetermined condition holds true.
*let a = 1;
while(a <= 50){
console.log(a)
a++;
}
let i = 0;
while(i <= 20){
console.log(i)
i=i+2;
}
let x = 1;
while(x <= 20){
console.log(x)
x=x+2;
}
//Do while:The do... while statement creates a loop that executes a specified
statement until the test condition evaluates to false.
*Decrement:
let a=20;
do{
console.log(a)
a--
}
while(a>=10)
*Increment:
let i=0;
do{
console.log(i)
i++
}
while(i<=20)
*var arr=[1,2,3,4,5,6,7,8,9]
for(let i=0;i<arr.length;i++){
if(i==5){
break;
}
console.log(arr[i])
}
var array1=[1,2,3,4,5,6,7,8,9,1,2,3,4,5]
console.log("The number of elements inside the array",array1.length)
for(let i=0;i<24;i++){
if(i==5){
continue;
}
console.log(array1[i])
}
**class State{
district1(){
console.log("clocktower in anantapur")
}
district2(){
console.log("kondareddyburju in kurnool")
}
}
x=new State();
x.district1();
x.district2();
output:clocktower in anantapur
kondareddyburju in kurnool
**class India{
Indianforces(Army,Airforce,Navy){
if(Army<3,Airforce<3,Navy<3){
else{
console.log("Indianforces one of the powerfull miltilary in the world
")
obj=new India
obj.Indianforces(2,2,2)
class Movies {
spirit=500
constructor(rrr,bahuballi,projectk){
console.log(rrr,bahuballi,projectk)
console.log(this.spirit)
}
devara(){
console.log(750)
}
}
obj=new Movies(1000,2000,3000)
obj.devara()
let name="vali"
switch(name) {
case "vali":
console.log("The name of the student is vali")
console.log("he scored in exams 100 percent")
break;
case "shahab":
console.log("The name of the student is shahab")
console.log("he scored in exams 110 percent")
break;
case "yash":
console.log("The name of the student is yash")
console.log("he scored in exams 80 percent")
break;
}
output:The name of the student is vali
he scored in exams 100 percent
let a=20
switch(a) {
case 10:
console.log("case 10 is a even number")
break;
case 20:
console.log("case 20 is a odd number")
break;
case 30:
console.log("case 30 is a just a number")
break;
}
setTimeout(function sum(){
console.log(100+50+30+80)
},5000)
output:260
setInterval(function sum(){
console.log(60+50+80+70)
},6000)
output:260
let a=20;
let b=40;
let exam = "a * b";
console.log (result=eval(exam));
output:800
output:true
let a=2
let b=5
let c=9
console.log(parseInt(b));
output:5
let a=22.5
let b=52.659
let c=9.0
console.log(parseFloat(b));
output:52.659
let a= 8523
console.log(isFinite(a))
output:true
**Reverse:
let i=0;
while(i<=10){
console.log(i)
i++;
}