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

Java Script

java script

Uploaded by

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

Java Script

java script

Uploaded by

2023csb1296
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Java script:

-const str = ‘this is a constant string’


-greet = ‘welcome ${name} to the JS’
-let str = ‘this is string class ’
- str.toUpperCase(‘str’) //changes to uppercase temporarily (non-destructive)
*destructive methods make changes to the original string
* non destructive just make a copy of the string
-str.trim(str) //removes the spaces at the begin and end of the string (non-destructive)
-console.log(str.slice(31)) // prints the string after 30 index
-str.length //finds the length of the string including spaces
-console.log(str.slice(index start)) or str.slice(index start, index end)

-let str = “we are doing chaining of methods”


-str.toUpperCase().slice(3,6).concat(“are”) //AREare (adds are to the sliced string)
-Math.random() //random number between 0 to 1
-Math.floor(Math.random()*10) //gives a random number from 0 to 9

-Const Arr =[1,2,3,4]


-arr.length //4 -arr[1] //2
-let arrcpy = arr //arrcpy makes the copy of arr and stores in it, it does not effect the
original one
-for(let elem of arrcpy){ console.log(elem)} //prints every element in arrcpy
-arr.pop() //remove an element at the end of the array
-arr.shift() // similar to pop but from starting also arr.unshift
-arr.push(5) //push 5 to the end of the list
-arr.unshift(‘0’) //adds the element at the starting of the array
-arr.reverse() //reverse the array
Version control system VCS:
Version control systems are a category of software tools that helps in recording changes
made to files by keeping a track of modifications done in the code.

-in terminal, ‘ls’ means list all the files


-git init //initialises empty git repository
-git status
-git add abc.txt
-git commit -m “learning the git”
-git add .
-git status //changes to be committed

-Const person={name : “praneeth”, age: 18, color:[‘yellow’,’red’]}


-Console.log(person[‘age’]+person[‘color’])
-console.log(person.color[1])
-for(let num = 0; num<=10;num++){console.log(num)}
-const fruits =[“apple”,”mango”,”banana”]
-for (fruit in fruits){console.log(fruit)} //fruits is a array containing fruits name
-for (key in person) { console.log(key)} //prints the keys in the person dictionary
-for (abc in person){console.log(${abc}:${person[abc]})}

-const array1= [1,4,9,16];


Const sqrtarray = [];
For (let num in array1){
Const ans = Math.sqrt(num);
Sqrtarray.push(ans);}

-const newArray = array1.map((elements) =>{console.log(elements);})


-const num =[12,23,43,2,4,223,22,42,23];
Const evenarray = num.filter( (elements) => {if (elements)%2 == 0{return true}})
-const sum = num.reduce( (acc,cur) => {return acc+cur;}, 0)

Const heading = document.getElementById(“heading”)


Heading.style.color = ‘red’
Heading.stye.padding = ‘25px’ //DOM: document object model

Const favMovies = document.getElementsByClassName(“fav-movie”)


//it is array but not a javascript array and don’t have any push or other options
-favmovies[0], -favmovies.length

-for ( let movie of favMovies) { movie.style.fontweight = “bold”;}

DOM Selectors:
*getElementById *getElementsByClassName *getElementByTagName
*querySelector *querySelectorAll

-const h1 = document.querySelector(“h1”)
-cosnt h2 = document.querySelectorAll(“h2”)
-const para= document.querySelector(“p”) -para.innerText

DOM properties:
-para.innerText += “this is added paragraph”
-para.textContent += “this is added text content”
-para.innerHtml = “ <em>highlight</em> added html line”

-const img = document.querySelector(“img”)


Img.getAttribute(“src”) //gets the sorce of the image

-const inp= document.querySelector(“input”)


Inp.setAttribute(“placeholder”, ‘username’) //set’s username text as a place holder
Inp.stlye.background = ‘red’

-const id = setInterval( () => {console.log(“hello”);} , 1000) //for every second prints hello
clearInterval(id) //stops printing hello

-const btn = document.querySelector(“#btn”);


function scream(){console.log(“scream”)}
function shout(){ console.log(“shout”)}
-inp.addEventListener(“keydown”, (event) => {
Let searchcontent = ‘’;
Searhccontent +=event.key
Ent.addEventListener(“click”, ()=> {console.log(searchcontent)})
})

-form.addeventListener(“submit”, (event)=> {
event.preventDefault();
console.log(“form submission prohibitted”)
})

You might also like