Revising the JS

Excel Sheet Link



console.log(variable_or_data);console.log()
integer_var = string_variable.indexOf('some_smaller_string');.indexOf()
integer_var = string_variable.lastIndexOf('some_smaller_string');.lastIndexOf()
string2_var = string1_variagle.toUpperCase();.toUpperCase()
string2_var = string1_variagle.toLowerCase();.toLowerCase()
sub_string = string1.slice(2,7);.slice()
replacedcherecterstring = string1.replace('car','bike');.replace()
extended_string = original_string.concat(string_to_be_added_further);.concat()
Proper_string = string_having_whitespace_in_front.trim();.trim()
char_at_3 = string.charAt(3);.charAt()


var len = arr.length;.length
arr.sort().sort()
arr,push(data).push()


alert(message_string)alert()
string name = messsage(messege_string);prompt()
let yes = confirm(messege_string);confirm()
arr.forEach(function fun(variable){ console.log(variable);}).forEach()


var main_var = document.getElementById('main');document.getElementById()
let NavImg_var = document.getElementByClassName('navimg');document.getElementByClassName()
let selector_var = document.querySelector('#navimg');.querySelector()


para_containg_var.style.display = 'block';.style.
para_containg_var.addEventListener('mouseover', function fun(){}).addEventListner()
setTimeout(function_name, time_after_which_function_run ,var1,var2,...)setTimeout()
setInterval(function_name, time_interval_of_function)run, var1, var2,...);setInterval()


let now = new Date();Date()
let month = now.getMonth();.getMonth()
let yr = now.getFullYear();.getFullYear()
let day = now.getDate();.getDate()
let hours = now.getHours();.getHours()
now.setDate(12);.setDate()
now.setMInutes(29);.setMinute()
now.setInterval(updateTime,1000); while updateTime is manually written function.setInterval()
id_name_of_a_element.innerHTML = new Date() ;.innerHTML

 

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