console.log("Hello World");
console.error('this error');
console.warn('sdsd');Let Re-Assign Value,Const Does not assign value
let age=30;
age=31;
console.log(age);
const old=30;
age=31;
console.log(old);const name='Akash';
const num=30;
const rating=4.5;
const isCoool=true;
const x=null;
const y=undefined;
let z;
console.log(typeof name);
console.log(typeof num);
console.log(typeof rating);
console.log(typeof isCoool);
console.log(typeof x);
console.log(typeof y);
console.log(typeof z);console.log('My name is'+ name +' and my age is :'+age);const hello=`My Name is ${name} and i am ${age}`;
console.log(hello);
const s='Hello World';
console.log(s.length);
console.log(s.toLowerCase());
console.log(s.toUpperCase());
console.log(s.substring(0,5).toUpperCase());
console.log(s.split(''));const numbers=new Array(1,2,3,4,5);
console.log(numbers);const fruits=['Apple','Orange','Mango','Graps',30,40];
console.log(fruits);fruits[3]='Banana';
console.log(fruits);console.log(fruits[1]);fruits.push('Pinaple');fruits.unshift('Watermalon');console.log(fruits.indexOf('Mango'));const person={
fisrtname:'Akash',
lastName:'Chauhan',
age: 20,
hobbies:['music','sports'],
addess:{
street:"Bhapara",
Village:"Gheti",
state:"Gujarat"
}
}
console.log(person);console.log(person.fisrtname,person.lastName);
console.log(person.hobbies[1]);
console.log(person.addess.Village);person.email='ac8572611@gmail.com';
console.log(person);const todos=[
{
id:1,
text:'Take out trash',
isCompleted:true
},
{
id:2,
text:'Program Done',
isCompleted:true
},
{
id:3,
text:'JAVASCRIPT',
isCompleted:false
},
];
console.log(todos);
console.log(todos[0].text);for(let i=0;i<5;i++)
{
console.log(`For loop number:${i}`);
}let i=0;
while(i<10)
{
console.log(`whilw loop no:${i}`);
i++;
}const c='10';
if(c===10)
{
console.log('x is 10');
}
const d=10;
if(d==10)
{
console.log('d is 10');
}const e=11;
const color =e>10?'red':'blue';switch(color)
{
case 'red':
console.log('color is red');
break;
case 'blue':
console.log('color is blue');
break;
default:
console.log('color is NOT red or blue ');
break;
}function addSum(num1,num2){
console.log(num1+num2);
}
addSum(5,7)const Addsum=(n1,n2)=>{
console.log(n1+n2);
}
Addsum(5,8);function Person(Fisrtname,LastName,Dob){
this.Fisrtname=Fisrtname;
this.LastName-LastName;
this.Dob=new Date(Dob);
}const p1=new Person('Akash','Chauhan','15-08-200');
const p2=new Person('Jigar','Chauhan','3-6-2000');
console.log(p1);
console.log(p2.Dob.getFullYear());class P3{
constructor(Fisrtname,LastName,Dob){
this.Fisrtname=Fisrtname;
this.LastName-LastName;
this.Dob=new Date(Dob);
}
getBirthYear(){
return this.Dob.getFullYear();
}
getFullYear()
{
return this.getFullYear();
}
}console.log(document.getElementById('my-form'));
console.log(document.querySelector('h1'));console.log(document.querySelectorAll('.item'));const btn=document.querySelector('.btn');
btn.style.background="red";
btn.addEventListener('click',(e)=>{
e.preventDefault();
document.querySelector('#my-form').style.background='#ccc';
console.log('click')
});const myForm=document.querySelector('#my-form');
const nameInput=document.querySelector('#name');
const emailInput=document.querySelector('#email');
const msg=document.querySelector('.msg');
const userList=document.querySelector('#users');
myForm.addEventListener('submit',onSubmit);
function onSubmit(e) {
e.preventDefault();
if(nameInput.value==='' || emailInput.value === ''){
msg.classList.add('error');
msg.innerHTML="Please Enter all fields";
setTimeout(()=>msg.remove(),3000);
}
else{
const li=document.createElement('li');
li.appendChild(document.createTextNode(`
${nameInput.value} : ${emailInput.value}`));
userList.appendChild(li);
nameInput.value='';
emailInput.value='';
}
}var add = (a,b) => a+b;var odd = n => n % 2;var random = () => Math.random();var shout = s => {
s = s.toUpperCase();
s = s + '!';
return s;
}function Counter () {
this.count = 0;
setInterval(() => this.count++, 1000);
}
var counter = new Counter();var data = ['one', 'two', 'three'];
var processed = data
.map(s => s.length)
.filter(length => length < 5);