Skip to content

Instantly share code, notes, and snippets.

View suhailgupta03's full-sized avatar
:octocat:

Suhail Gupta suhailgupta03

:octocat:
View GitHub Profile
// starts and ends with a single quote
var myUserName = 'suhail03'; // albhabets + numbers
// starts and ends with a double quote
var myFullName = "suhail gupta"
// starts and ends with a backtick
var myTwitterUserName = `suhailg03`;
console.log(myUserName);
// The following is an incorrect way
// to represent multiple single quotes
// in a string which already starts with a
// single quote
// var singleQuoteString = 'suhail 'gupta'';
// console.log(singleQuoteString);
var myNewVariable = "suhail 'gupta'";
console.log(myNewVariable);
var string1 = "mahima";
var string2 = "bhat";
// can concatenate (join) 2 or multiple strings
// using + operator
var fullName = string1 + " " + string2
// string1 gets added to an empty string (which is a space here)
// which then gets added to string2
// mahima + " " + bhat
console.log(fullName);
var firstName = "Aditya Gupta";
var lastName = "Gupta";
var x = firstName + " " + lastName + " is a student with alma better";
console.log(x);
var fullName = `${firstName} ${lastName} is a student with alma better`;
console.log(fullName);
var news = `Karnataka Election Result 2023 LIVE | Shivakumar Says
var oneWay = {}
var anotherWay = new Object();
// Both of them above create an object (empty object)
oneWay.city = "bangalore";
anotherWay.city = "mysore";
console.log(oneWay)
console.log(anotherWay);
var person = {
name: 'manoj',
age: 20,
employee: {
id: 200,
role: 'software engineer',
duration: 2,
salary: {
rupees: 123456,
recentlyChanged: false
const response = {
mode: 'none'
}; // Objects are Javascript specific!!!!!!!
// Use strings to send data in the network!!!
console.log(response);
// WE WILL NEED TO CONVERT OBJECT INTO STRING
var myNewString = JSON.stringify(response);
console.log(myNewString);
function greet() {
console.log("Good evening, friends!");
console.log("One more statement before the fn exits");
}
// greet is the name of the function [entity]
greet(); // calling the function named greet
// () are mandatory to call a function
console.log("After the function call");
console.log("hello");
console.log("hello 2");
console.log("hello 3");
var z = 100
function greet() {
console.log("Good evening, friends!");
console.log("Good morning, friends!");
} // Here the fn will EXIT, which means
// that it has carried out its job
function greet(message, nameOfThePerson) {
var greetMessage = `Hello, ${nameOfThePerson}! ${message}`;
console.log(greetMessage);
}
greet("Good evening", "Mahima");
greet("Good morning", "Adity");
greet("Arjun", "Good evening");