Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
15 views

Java Notes

JavaScript is a popular programming language used to create interactive and dynamic web pages. Key concepts include variables, data types, functions, loops, operators, and objects. JavaScript can be embedded in HTML pages and used to handle events, validate forms, and create animations.

Uploaded by

taniaasharma25
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Java Notes

JavaScript is a popular programming language used to create interactive and dynamic web pages. Key concepts include variables, data types, functions, loops, operators, and objects. JavaScript can be embedded in HTML pages and used to handle events, validate forms, and create animations.

Uploaded by

taniaasharma25
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

java scrpt is a popular progm.

lang that is commonly used for creating intracting


and dynamic website.
key features and concepts of js:
js has a syntax that is simmilar to the other progrming lang like c nd java
it uses semiccoloms to end the statement and {} to define the block of code

variables:are used to store the value in js nd can be defined using var , let or
const key words

data types: js supports severl data types incliding numbers string bollen array
objects and null
function are the block code that can be reused mult tyms
can be defined using the fumction kayword and can take parameters as input and
return val as op

loops : allows u to execute the same block of code mult tyms


js supports for, while, and do while loop

variables in js :
1) var hello=10;

2) let hello=10;

3) const hello=10;

conditions to define varianles in js :

1) names can contain letters,digits underscores and $signs


names must begin wid a letter can begin wid dollor sign , names is always case
senstive reserve words cannot be used as a variable

comments in js:used to exp the code and meke it more readable, for commenting use//

multiline comments in js: /*

how to embed js in html :


1) internal js: to add js in html pg we can open the script tag inside the head
sec of the pg
2) external js: js can also be pleced as external files with a specific syntax:
<script src="path of the js"> </script>
3) inline method
how to embed js in html :
.)we can use the script element which is used to define a client side script in a
html document
syntax: <script src="path of the js"> </script>
.)we can use the src attribute of the script element to load an external java
script file

operators in js:are used to assingn the values to the variables as well as to


perform some actions on values
types of operators:
1) arithmetic operator:
2) assingnment operator
3)comparision operator
4)string operator
5)logical operator
6)bitwise operator
7)type operator

AERUTHMETIC operator:these operator are used to perform mathematical operations on


the numerical values
addition used to add 2 values togther
subtraction :usded to sub one value from another
multiplication used to ultiply two values
division diveds the one value by another
modulos: returns the reminder of the division operation
increment and decrement : used to increse or decres the value of a variable

comparision operators: are ues to compare two values and return a bollean value
1)=:returns true if both the values are equal
2)not equal : returns true if both the values are not equal
3)> than : returns true if the value one is> tha value two
4)< than : retrns true if value one is < than value 2
5)>= : retruns true if the value on eis> than or= to value two
6)<=:

logical operator : are used to combine or invert the bollen value


and:returns true if both operands are true
or: returns true if atleast one opernd is true
not: inverts the bollean value of an operand

assignment operator: are used to assingn values to the variables


equal to : assings a value to a variable
+=: add a value to a variable and assings the result
-=: sub the values from a variable and assigns the result
*=:mul the variavbles by a value and assigns a result
/=: devides a variable by values and assingn the result

Bitwise operator: are used to perform the operations on the binary no.s bitwise
operator only performs the operatons on the integers the integers values are
converted into the binary then the operation is performed and the binaary is
converted back into the integer.
1) bitwise and (&) : it will return 1 if both the coreesponding bits of both
operands 1
2) bitwise or =(|) it will return 1 if any of the either oprend
3) xor: returns 1 in each bit position for which the correspondiing bits are 1 but
not both operands are 1
4) bitwise not: inverts the bits of opreand
5) left shift : shifts the bit of first operand to the left by the no. of positions
specified by the second operand
6) right shift : shifts the bit of first operand to the right by the no. of
positions specified by the second operand

use cases of js
1 to handel the events like button clicks ,mouse movement , keyboard inputs
2) to manupulate the html elements ,we can use this to change the content and
styling of html element
ex: we can change the text inside the paragraph or we can chng the bgclr or txt
clr.
3) validating the user inputs
4) we can use this for creating the annimations, for performing the calculations

js events :

when js is used in html pages js can react on these events


an html event can be something the browser does or something a user does
ex of html events
1)an html webpg has finished the loading
2) an html input field was changed
3) an html button was clicked

js objects :

objects are similar to the variables but objects can contain multiple values
ex:- const bike={type:"bullet","color:red","model:2012"};

CREATING ANNIMATION USING JS:

to create annimation using js we can use the followinhg steps


1) u need to create the html element that u want to annimate this can be a simple
division ,image or any other element that u want to move rotate or change the
properties of
2)now u need to add event listener to the element this will b etrigger when the
elemnt is clicked ,hoover or any other specified
3) in the event listener function we can use the js to chnge the properties of the
element for ex: to move an element u can change its left or top css properties
using the style properties
4) to create a smooth annimation we can use a set interval function or req
annimation frame

<button onclick="displayDate()">click here</button> =this line of code creates a


button wid a txt click here and an on click attribute that ca;ss adisplay date
function when clicked
<script> function displayDate() = this is the displayed date function that
will return the out come on the same pg
{document.getElementById("demo").innerHTML=Date();}</script>
<p id="demo"></p> = this line creates an html paragraph wid the id demo that
will return tthe date when the button is clicked
on click= whwn a user clicks an html element
on change = when an html element has been chnged
on mouse over= when the user moves the mouse over the html element
on load = when the browser has finished loading the page
on key down = when the user pushes the keyboard key
on mouse out=when the user moves the mouse away from the html element

objects: an object is a collection of key value pair where the kwys are the string
and the values can be any data type

var name ="tania";


var num = 9888510972;
var

when we have to execute a block of code on the basis of some condition we can use
the if ststement , if else statement ,nested if statement

if ststement : if (condition) pass (what it will perform), fail (what it will


perform)

the condition is the logic that u want to test , if the condition will pass it will
return the value if true ,if the condition fail the vakue if fails

if( condition ) {
//block of code//
}
if condition{
// block of code if condition is true
}
else{
// block of code if condition is false
}

var age = 50

if (age=>50){
console.log ("elder")

var age = 50

if (age=>50){
console.log ("elder")

}
else if (age>10 && age <16 ){
console.log("kid")
}
else if (age>18){
console.log("adult")
}
else{
coonsole.log("invalid age")

switch case
the script statement and js is a controling structure that allows u to specify or
exescute a differnt block of code depending upon a specific value it is used as an
alternative to if else ladder when u have multiple condition to chgeck against a
single value
sysyntax
let x=tania;
switch(x){case "tania"

the break staement is used to exit the switch and prevent the code from being
executed
the default statement is optional and is executed when there are no expression
matches or no case value match then it will return the content of the default
statement

ternary operators

the ternary operator is a short hand property to write an if else statement it


takes the arguments in the form of condition? value1 :value2
where condition is a boolen aexpresion and value1 and value 2 are expresion of any
type
if the condition is true it will return value 1 if the condition is false it will
return vlue 2
let x =10;
let y=20;
let max;
max=(x>y)? x:y;
console.log(max);

loops :

loops are a common way to control the flow of aprogram that allows u to repeat a
block of code for specific number of tym

for vs while loop

a for loop is a control flow ststement used for executing a block ogf code for a
specific no. of tyms
it contains 3 components
1 initialization : it sets the starting point
2 condition : the condtion defines the termination condition
3 increment / decrement : updates the loop control variable

for loops are usedc when u know the exact no. of itteration required

while loop
it is used for execcuting a block of code as long as a certain condition is true
it only has a condition that check before each itteration
it the condition is true the loop body is executed and the process contnied until
the condition become false
while loops areful when u dont know for how many tyms the loop is to be executed

syntex : for loop

for(initializtaion; condition;inc/dec)
example : for (let i=0; i<5; i++){console.log(i);}
syntax :while loop

while(cond){
}

examp: let i=0;


while(i<5){console.log (i);
i++;
}

programs
1 write a for loop that prints the no. 1 to 10
2write a for loop that prints a even no from 2 till 20
3 write a for loop that calculate the sum of no. from 1 to 100 the result must be
stored in a variable called total sum
4 write a for loop that prints a reverse order of no.s from 10to 1
5 write a for loop that prints a squre root of nos.1to 10

You might also like