Revising the JS
Excel Sheet Link
printing on console
console.log(variable); //will print out the data in variable
// To declare variable
let var,a ,b
const var
int var
char var
// The string variable and string manipulation
let name = "Suppandi";
let message = "is gigachad.";
let combine = name + " " + message;
console.log(combine); //1
let money = 24000;
console.log(name + `have ${money} dollars ` ) ;
var positionOfpainname = name.indexOf('pa'); //2
var positionfromlastofpa = name.last.indexOf('pa'); //3
var substring = name.slice(2,7); // will store from cherecter 2 to 7 in string name to string substring //4
var replaced = string1.replace('string', 'suppandi'); // will replace string word by suppandi in string stored in variable string1 //5
making string to all uppercase :
let upper = string1.toUpperCase(); // all cherecter in string in string1 is converted to uppercase and then stored to upper named string and string1 is unaffected//6
similarly
let lower = string1.toLowerCase(); //7
joining two string
can be done by + but bakchodi to krni ha hme toh
original_string.concat(string_to_be_added);//8
let proper_string = string.trim() ; will remove whitespace in front of string if present
char3 = string.charAt(3);
// Variable in javascirpt and object and arrays , if else , switch case :
variable type
let a = 'u'; // can be changed
const b = 3 ; // can't be changed again
The If-else, switch-case as it is in c and c++
declearing a struct type variable is done as and called object
let employee = {
name : 'suppandi',
salary:10,
channel:'suppanid-daku',
}
and reffered as
employee.channel , employee.salary , employee.channel ,employee['salary']
array-Decleration
let arr = new Array(1,2,4,'devesh',true,2.3,"harry",`suppandi`);
reffered as
arr[3]
length is given as arr.length
for sorting arr.sort()
adding some more data in end of array use arr.push('Deepak');
//Function Declearation
function function_name (variable1,variavle2,...){
//codes
}
// The JavaScript Alert , Confirm . prompt
done as
alert("this messege");
prompt is a value , string ,
let name = prompt('what is your name ?','');
confirm is a vlaue,, true or false
deletepost = confirm ("do you really want to delete post ");
if-eles to do things
// Loops time for while do-while
syntax is same as that was of c and c++
more syntax are there :
//1
for(let i =0 ; i<arr.len; i++){
console.log("element is " + arr[i]);
}
//2 modern javascript
arr.forEach(
function function_name(variable1){
console.log('element is ' + variable1 );
}
)
// 3 modern javascript
for ( element of function ){ console.log( 'element is ' + element )}
for object itereation
for ( key in employee ){ console.log(`The ${key} of the employee is ${employee[key]}`);
while and do while have same syntax as in c ,c++
// DOM manipulation The crazy part
element in html havin id say main
let main_var = document.getElementById('main');
we can do
console.log(main_var);
element in html having class container
let container_var = document.get.ElementByClassName('container');
for manipulating css
selectors in js
let selector_var = document.querySelector('.container')
let selector_var_by_id= document.querySelector('#navigation'); // will select the css of element
let queryselector_var = documetn.qureySelectorAll('#navigation>li');
we can change styling as
step1 : get the element let para_var = document.getElementById('para');
step2 : now change css para_var.style.display = 'flex'/'none'/'block';
step3 : if want to add event add event listner
para_var.addEventListener('mouseover', function run(){alert('mouseover working and mouse is inside para')'})
// Time out and time interval functions
setTimeout(function_name_to_run, time_in_ms, variable1, variable2,...);
setInterval(function_name_to_run, time_of_interval_in_ms, variable1, variable2, ..);
// How to get a Date as a programmer in JavaScript
date is a data is stored in variable
let now = new Date(); // print in bigger formatby using console.log(now);
we can give argument as
let dat = new Date(3020); ore dat = new Date(2020-09-03);
let newDate = new Date(2023-,4,5,5,5,5,5) ; will have some meaning date reaches till time
we can scrapout the elements inside the date
yr = newDate.getyFullYear();
mon = newDate.getMonth();
day = newDate.getDate();
hour = newDate.getHours();
we can do set too
as
newDate.setDate(15);
newDate.setMinute(29);
newDate.setInterval(function_to_update, time_interval);
Comments
Post a Comment