JavaScript Lab 1

// How to print
//console.log("Hello");

// There are both string
"String 1";
'string 2';

// This is a number.
42;


// Variables

// var x = "One";
// console.log(x);
// x = "Funny";
// console.log(x);

let m = "Mottel";
const h = "goodbye";
console.log(m,h);

// let , var, and const are not the same.
// For now use let.

// Boolean
true;
false;

// How to make null
let j;
j = null;
console.log(j);

// // Declare the Variale.
// let x = 0;

// // We can Add
//  x = x + 5;
 
// //  Multiply
// x = x * 5;

// // Subtract
// x = x - 5;

// // divide
// x = x / 4;
 
// // Another way to add
// x += 5;

// // Increment and decrement
// x++;
// x--;

// Adding boolenas
// let x = true;
// x += 5;

// Parsing Strings
// let x = "42.2";
// // x = parseInt(x);
// x = parseFloat(x);
// x *= 2; 

// x = String(x);

//  Number to Sting 
// let x = 42;
// x = x.toString();
// x += "hahahahhaha";

// Casting
// let x = 23;
// x = Number(x);
// x *= 2;

let x = 23;
x = String(x);
x += "weeeeeeee";



//  Print the result
console.log(x);

// // This is object
// let person = {
//     firstname: "yash",
//     lastname : "patel",
//     age : 24, 
//     isTeacher : false
// };

// // person.lastname = "hello";

// // Printing an attribute.
// console.log(person.lastname);

// // Printing the object
// console.log(person);
// console.log(person["age"]);


let ages = [28 ,26 ,12, 20, 7,15];

// 
console.log(ages);
console.log(ages[2]);

// Shift
let j = ages.shift();
console.log(j);
console.log(ages);

// unshift
ages.unshift(2020);
console.log(ages);

// pop and Push
ages.pop();
console.log(ages);
ages.push(3000);
console.log(ages);


// Convert to string
console.log(ages.length);
console.log(ages.join(" "));

Comments

Popular posts from this blog

5th sem OOPJ Write an interactive program to print a diamond shape. For example, if user enters the number 3, the diamond will be as follows:

SQL Lab 3

SQL Lab 6