diff --git a/C/03_Day_Variable/readme.md b/C/03_Day_Variable/readme.md index 822912a..cb2617b 100644 --- a/C/03_Day_Variable/readme.md +++ b/C/03_Day_Variable/readme.md @@ -78,6 +78,36 @@ When programming in C, adhering to proper variable naming conventions is essenti - While there is no strict limit on variable name length, most compilers support up to 31 characters for variable names (though modern compilers may support longer names). It's good practice to use meaningful and concise names. - **Best Practice:** Keep names reasonably short but descriptive. + + + + + +## Naming Convention + +1. **camelCase** + +- Start with lowercase letter. Capitalize the first letter of each subsequent word. + +- Example : `myVariableName` + + +2. **snake_case** + + +- Start with an lowercase letter . Separate words with underscore. + +- Example : `my_variable_name` + + + +Keep a Good and Short Name + +- Choose names that are descriptive but not too long. It should make it easy to understand the variable's purpose. + + +- Example : `age` , `first_name` , `isMarried`; + ## Best Practices for Naming Variables 1. **Use Descriptive Names:** diff --git a/C/04_Format Specifiers/.vscode/settings.json b/C/04_Format Specifiers/.vscode/settings.json new file mode 100644 index 0000000..1de26dd --- /dev/null +++ b/C/04_Format Specifiers/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "*.ejs": "html", + "stdio.h": "c" + } +} \ No newline at end of file diff --git a/C/04_Format Specifiers/StartedCode/index b/C/04_Format Specifiers/StartedCode/index new file mode 100755 index 0000000..9a405a4 Binary files /dev/null and b/C/04_Format Specifiers/StartedCode/index differ diff --git a/C/04_Format Specifiers/StartedCode/index.c b/C/04_Format Specifiers/StartedCode/index.c new file mode 100644 index 0000000..3151957 --- /dev/null +++ b/C/04_Format Specifiers/StartedCode/index.c @@ -0,0 +1,47 @@ +#include + +int main() { + // Defining variables of different types + int age = 30; // Integer variable + float height = 5.9; // Floating-point variable + char initial = 'A'; // Character variable + char name[] = "Alice"; // String variable + + // Displaying an integer value + printf("Age: %d\n", age); // %d format specifier displays an integer + + // Displaying a floating-point value with one decimal place + printf("Height: %.1f meters\n", height); // %.1f format specifier displays a float with one decimal place + + // Displaying a single character + printf("Initial: %c\n", initial); // %c format specifier displays a single character + + // Displaying a string + printf("Name: %s\n", name); // %s format specifier displays a string + + // Demonstrating unsigned integer + unsigned int score = 150; // Unsigned integer variable + printf("Score: %u\n", score); // %u format specifier displays an unsigned integer + + // Demonstrating hexadecimal format + int hexValue = 255; // Integer variable + printf("Hexadecimal: %x\n", hexValue); // %x format specifier displays an integer in hexadecimal format + + // Demonstrating scientific notation for floating-point numbers + float largeNumber = 123456.789; // Floating-point variable + printf("Large Number: %e\n", largeNumber); // %e format specifier displays a float in scientific notation + + // Demonstrating pointer format + int *ptr = &age; // Pointer to integer + printf("Address of age: %p\n", (void*)ptr); // %p format specifier displays the memory address of the pointer + + // Demonstrating width and precision + float preciseValue = 3.14159; // Floating-point variable + printf("Precise Value: %.3f\n", preciseValue); // %.3f format specifier displays a float with three decimal places + + // Demonstrating width with padding + int number = 42; // Integer variable + printf("Number with width: %5d\n", number); // %5d format specifier displays an integer with a minimum width of 5, padded with spaces + + return 0; +} diff --git a/C/04_Format Specifiers/readme.md b/C/04_Format Specifiers/readme.md new file mode 100644 index 0000000..12054c8 --- /dev/null +++ b/C/04_Format Specifiers/readme.md @@ -0,0 +1,120 @@ +# C Format Specifiers + +In many programming languages (like Python, Java, and C++), you use print functions to display the value of a variable. However, in C, things are a bit different. + +In C programming, format specifiers are used in functions like `printf` and `scanf` to control the format of input and output. These specifiers tell the function how to interpret or display the data. They are crucial because C does not have higher-level features for formatted input and output like some other languages do. + + + +**C programming mein, format specifiers `printf` aur `scanf` jese functions mein use kiye jaate hain taaki input aur output ka format control kiya ja sake. Ye specifiers batate hain ki data ko kaise samjha ya dikhaya jayega. Ye zaroori hote hain kyunki C mein formatted input aur output ke liye high-level features nahi hote jaise kuch dusri programming languages mein hote hain.** + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Format SpecifierDescriptionExample Syntax
%cFor character typeprintf("%c", 'A');
%dFor signed integer typeprintf("%d", -123);
%e or %EFor scientific notation of floatsprintf("%e", 123.456);
%fFor float typeprintf("%f", 3.14);
%g or %GFor float type with the current precisionprintf("%g", 0.000123);
%iFor signed integer type (same as %d)printf("%i", -123);
%ld or %liFor long integer typeprintf("%ld", 1234567890L);
%lfFor double typeprintf("%lf", 3.1415926535);
%LfFor long double typeprintf("%Lf", 3.14159265358979L);
%luFor unsigned int or unsigned longprintf("%lu", 123456789UL);
%lli or %lldFor long long integer typeprintf("%lld", 123456789012345LL);
%lluFor unsigned long longprintf("%llu", 123456789012345ULL);
%oFor octal representationprintf("%o", 255);
%pFor pointer typeprintf("%p", (void *)&num);
%sFor string typeprintf("%s", "Hello, world!");
%uFor unsigned intprintf("%u", 123456);
%x or %XFor hexadecimal representationprintf("%x", 255);
%nPrints nothing but stores the number of characters printed so far into an integer variableprintf("Count: %n", &count);
%%Prints the % characterprintf("Percentage: %%");
+ diff --git a/C/06_Day_Data_Type/Starter Code/dataType.c b/C/06_Day_Data_Type/Starter Code/dataType.c new file mode 100644 index 0000000..093d6a4 --- /dev/null +++ b/C/06_Day_Data_Type/Starter Code/dataType.c @@ -0,0 +1,17 @@ +#include + + +int main(){ + /** + * Declares and initialise an integer variable. + */ + + int a = 12; + + /** + * use %d if you want to print a number + */ + + float out; + printf("%d" , a); +} \ No newline at end of file diff --git a/C/06_Day_Data_Type/Starter Code/readme.md b/C/06_Day_Data_Type/Starter Code/readme.md new file mode 100755 index 0000000..010e288 Binary files /dev/null and b/C/06_Day_Data_Type/Starter Code/readme.md differ diff --git a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/catergory.model.js b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/catergory.model.js index f14d1f2..f552ef2 100644 --- a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/catergory.model.js +++ b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/catergory.model.js @@ -3,19 +3,19 @@ import { Schema , model} from "mongoose"; const categorySchema = new Schema({ - name: { + cName: { type: String, required: true, unique: true, lowercase: true, }, - description: { + cDescription: { type: String, required: true, unique: true, lowercase: true, }, - photo: { + cPhoto: { type: String, }, diff --git a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/order.model.js b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/order.model.js index e69de29..ea90f51 100644 --- a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/order.model.js +++ b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/order.model.js @@ -0,0 +1,44 @@ +import mongoose, { Schema, model } from "mongoose"; + +const orderItemSchema = new Schema({ + productId: { + type: mongoose.Schema.ObjectId, + ref: "product", + }, + quantity: { + type: Number, + require: true, + }, +}); + +let OrderModel = new Schema( + { + oPrice: { + type: Number, + require: true, + }, + + oItems: { + type: [orderItemSchema], + }, + address:{ + type:String, + require:true, + }, + + status:{ + type: String, + enum: ['Pending' , 'Cancelled' , 'Delivered'], + default: 'Pending', + + }, + + customer: { + type: mongoose.Schema.ObjectId, + ref: "user", + }, + }, + { timestamps: true } +); + +export const Category = model("Category", OrderModel); diff --git a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/product.model.js b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/product.model.js index e18b547..3c351d4 100644 --- a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/product.model.js +++ b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/product.model.js @@ -2,43 +2,50 @@ import mongoose, { Schema, model } from "mongoose"; let productSchema = new Schema({ - name:{ + Pname:{ type: String, require: true, lowercase : true, }, - description:{ + pColor:{ + type: String, + require: true, + lowercase : true, + }, + + + pDescription:{ type: String, require: true, lowercase : true, }, - price:{ + pPrice:{ type: Number, require: true, lowercase : true, }, - stock:{ + pStock:{ type: Number, default : 1, }, - discount:{ + pDiscount:{ type: Number, require: true, lowercase : true, }, - category:{ + pCategory:{ type: Schema.Types.ObjectId, ref: 'category', require: true, }, - photo:{ + pImage:{ type: String, } diff --git a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/user.model.js b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/user.model.js index fa592d1..50ea01d 100644 --- a/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/user.model.js +++ b/Express/15_Day_MongoDb_Module_Demo/02_Day_E-Commerce/models/user.model.js @@ -2,7 +2,7 @@ import { Schema , model} from "mongoose"; const userSchema = new Schema( { - username: { + userName: { type: String, required: true, unique: true, diff --git a/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package-lock.json b/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package-lock.json new file mode 100644 index 0000000..db80240 --- /dev/null +++ b/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package-lock.json @@ -0,0 +1,246 @@ +{ + "name": "02_Day_E-Commerce", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "dependencies": { + "mongoose": "^8.5.2" + } + }, + "node_modules/@mongodb-js/saslprep": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.8.tgz", + "integrity": "sha512-qKwC/M/nNNaKUBMQ0nuzm47b7ZYWQHN3pcXq4IIcoSBc2hOIrflAxJduIvvqmhoz3gR2TacTAs8vlsCVPkiEdQ==", + "license": "MIT", + "dependencies": { + "sparse-bitfield": "^3.0.3" + } + }, + "node_modules/@types/webidl-conversions": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/@types/webidl-conversions/-/webidl-conversions-7.0.3.tgz", + "integrity": "sha512-CiJJvcRtIgzadHCYXw7dqEnMNRjhGZlYK05Mj9OyktqV8uVT8fD2BFOB7S1uwBE3Kj2Z+4UyPmFw/Ixgw/LAlA==", + "license": "MIT" + }, + "node_modules/@types/whatwg-url": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/@types/whatwg-url/-/whatwg-url-11.0.5.tgz", + "integrity": "sha512-coYR071JRaHa+xoEvvYqvnIHaVqaYrLPbsufM9BF63HkwI5Lgmy2QR8Q5K/lYDYo5AK82wOvSOS0UsLTpTG7uQ==", + "license": "MIT", + "dependencies": { + "@types/webidl-conversions": "*" + } + }, + "node_modules/bson": { + "version": "6.8.0", + "resolved": "https://registry.npmjs.org/bson/-/bson-6.8.0.tgz", + "integrity": "sha512-iOJg8pr7wq2tg/zSlCCHMi3hMm5JTOxLTagf3zxhcenHsFp+c6uOs6K7W5UE7A4QIJGtqh/ZovFNMP4mOPJynQ==", + "license": "Apache-2.0", + "engines": { + "node": ">=16.20.1" + } + }, + "node_modules/debug": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.6.tgz", + "integrity": "sha512-O/09Bd4Z1fBrU4VzkhFqVgpPzaGbw6Sm9FEkBT1A/YBXQFGuuSxa1dN2nxgxS34JmKXqYx8CZAwEVoJFImUXIg==", + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "license": "MIT" + }, + "node_modules/kareem": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.6.3.tgz", + "integrity": "sha512-C3iHfuGUXK2u8/ipq9LfjFfXFxAZMQJJq7vLS45r3D9Y2xQ/m4S8zaR4zMLFWh9AsNPXmcFfUDhTEO8UIC/V6Q==", + "license": "Apache-2.0", + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/memory-pager": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", + "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", + "license": "MIT" + }, + "node_modules/mongodb": { + "version": "6.7.0", + "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-6.7.0.tgz", + "integrity": "sha512-TMKyHdtMcO0fYBNORiYdmM25ijsHs+Njs963r4Tro4OQZzqYigAzYQouwWRg4OIaiLRUEGUh/1UAcH5lxdSLIA==", + "license": "Apache-2.0", + "dependencies": { + "@mongodb-js/saslprep": "^1.1.5", + "bson": "^6.7.0", + "mongodb-connection-string-url": "^3.0.0" + }, + "engines": { + "node": ">=16.20.1" + }, + "peerDependencies": { + "@aws-sdk/credential-providers": "^3.188.0", + "@mongodb-js/zstd": "^1.1.0", + "gcp-metadata": "^5.2.0", + "kerberos": "^2.0.1", + "mongodb-client-encryption": ">=6.0.0 <7", + "snappy": "^7.2.2", + "socks": "^2.7.1" + }, + "peerDependenciesMeta": { + "@aws-sdk/credential-providers": { + "optional": true + }, + "@mongodb-js/zstd": { + "optional": true + }, + "gcp-metadata": { + "optional": true + }, + "kerberos": { + "optional": true + }, + "mongodb-client-encryption": { + "optional": true + }, + "snappy": { + "optional": true + }, + "socks": { + "optional": true + } + } + }, + "node_modules/mongodb-connection-string-url": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mongodb-connection-string-url/-/mongodb-connection-string-url-3.0.1.tgz", + "integrity": "sha512-XqMGwRX0Lgn05TDB4PyG2h2kKO/FfWJyCzYQbIhXUxz7ETt0I/FqHjUeqj37irJ+Dl1ZtU82uYyj14u2XsZKfg==", + "license": "Apache-2.0", + "dependencies": { + "@types/whatwg-url": "^11.0.2", + "whatwg-url": "^13.0.0" + } + }, + "node_modules/mongoose": { + "version": "8.5.2", + "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-8.5.2.tgz", + "integrity": "sha512-GZB4rHMdYfGatV+23IpCrqFbyCOjCNOHXgWbirr92KRwTEncBrtW3kgU9vmpKjsGf7nMmnAy06SwWUv1vhDkSg==", + "license": "MIT", + "dependencies": { + "bson": "^6.7.0", + "kareem": "2.6.3", + "mongodb": "6.7.0", + "mpath": "0.9.0", + "mquery": "5.0.0", + "ms": "2.1.3", + "sift": "17.1.3" + }, + "engines": { + "node": ">=16.20.1" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/mongoose" + } + }, + "node_modules/mpath": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.9.0.tgz", + "integrity": "sha512-ikJRQTk8hw5DEoFVxHG1Gn9T/xcjtdnOKIU1JTmGjZZlg9LST2mBLmcX3/ICIbgJydT2GOc15RnNy5mHmzfSew==", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/mquery": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/mquery/-/mquery-5.0.0.tgz", + "integrity": "sha512-iQMncpmEK8R8ncT8HJGsGc9Dsp8xcgYMVSbs5jgnm1lFHTZqMJTUWTDx1LBO8+mK3tPNZWFLBghQEIOULSTHZg==", + "license": "MIT", + "dependencies": { + "debug": "4.x" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/sift": { + "version": "17.1.3", + "resolved": "https://registry.npmjs.org/sift/-/sift-17.1.3.tgz", + "integrity": "sha512-Rtlj66/b0ICeFzYTuNvX/EF1igRbbnGSvEyT79McoZa/DeGhMyC5pWKOEsZKnpkqtSeovd5FL/bjHWC3CIIvCQ==", + "license": "MIT" + }, + "node_modules/sparse-bitfield": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", + "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", + "license": "MIT", + "dependencies": { + "memory-pager": "^1.0.2" + } + }, + "node_modules/tr46": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-4.1.1.tgz", + "integrity": "sha512-2lv/66T7e5yNyhAAC4NaKe5nVavzuGJQVVtRYLyQ2OI8tsJ61PMLlelehb0wi2Hx6+hT/OJUWZcw8MjlSRnxvw==", + "license": "MIT", + "dependencies": { + "punycode": "^2.3.0" + }, + "engines": { + "node": ">=14" + } + }, + "node_modules/webidl-conversions": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-url": { + "version": "13.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-13.0.0.tgz", + "integrity": "sha512-9WWbymnqj57+XEuqADHrCJ2eSXzn8WXIW/YSGaZtb2WKAInQ6CHfaUUcTyyver0p8BDg5StLQq8h1vtZuwmOig==", + "license": "MIT", + "dependencies": { + "tr46": "^4.1.1", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=16" + } + } + } +} diff --git a/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package.json b/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package.json new file mode 100644 index 0000000..1fb6221 --- /dev/null +++ b/Express/15_Day_MongoDb_Module_Demo/03_Day_Hospital-Management/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "mongoose": "^8.5.2" + } +} diff --git a/Express/Rayzor Pay/StarterCode/index.js b/Express/Rayzor Pay/StarterCode/index.js index df994d9..3cf437a 100644 --- a/Express/Rayzor Pay/StarterCode/index.js +++ b/Express/Rayzor Pay/StarterCode/index.js @@ -11,7 +11,7 @@ import cors from 'cors'; var corsOptions = { origin: 'http://localhost:3000/', optionsSuccessStatus: 200 // some legacy browsers (IE11, various SmartTVs) choke on 204 - } +} const app = express() diff --git a/JavaScript/07_Day_Data_Types/07_Statar_Code/script.js b/JavaScript/07_Day_Data_Types/07_Statar_Code/script.js index 237b665..8a26f57 100644 --- a/JavaScript/07_Day_Data_Types/07_Statar_Code/script.js +++ b/JavaScript/07_Day_Data_Types/07_Statar_Code/script.js @@ -3,9 +3,9 @@ /* -------------------------------------------------------------------------- */ -/* ------------------- treat all Js code as newer version ------------------- */ -"use strict" + +"use strict" // ------------------- treat all Js code as newer version ------------------- /* ------- Number: Represents both integer and floating-point numbers ------- */ console.log('_____________________Number _______________________________') diff --git a/JavaScript/08_Day_Data_Type_convert/readme.md b/JavaScript/08_Day_Data_Type_convert/readme.md new file mode 100644 index 0000000..c406c84 --- /dev/null +++ b/JavaScript/08_Day_Data_Type_convert/readme.md @@ -0,0 +1,313 @@ +# JavaScript Data Type Conversion + +## Overview + +In JavaScript, **data type conversion** refers to the process of changing a value from one type to another. JavaScript provides ways to convert types explicitly using functions, and it also performs automatic type conversion in certain situations. This guide will help you understand both explicit and implicit type conversion. + +## Explicit Type Conversion + +**Explicit type conversion** means manually converting a value from one type to another using JavaScript functions. + +### String to Number + +- **`Number()` Function**: Converts a string to a number. If the string contains non-numeric characters, it returns `NaN` (Not-a-Number). + + ```javascript + let str = '42'; + let num = Number(str); // Converts '42' to 42 + console.log(num); // Output: 42 + ``` + + *Hinglish Explanation:* `Number()` function se hum string ko number me convert kar sakte hain. Agar string mein numeric characters nahi hain, to `NaN` milta hai. + +- **`parseInt()` Function**: Converts a string to an integer. It parses the string until it encounters a non-numeric character. + + ```javascript + let str = '42px'; + let intValue = parseInt(str); // Converts '42px' to 42 + console.log(intValue); // Output: 42 + ``` + + *Hinglish Explanation:* `parseInt()` function se string ka integer part convert hota hai. Extra characters ko ignore kar deta hai. + +- **`parseFloat()` Function**: Converts a string to a floating-point number. It also parses until it hits a non-numeric character but handles decimal points. + + ```javascript + let str = '42.5abc'; + let floatValue = parseFloat(str); // Converts '42.5abc' to 42.5 + console.log(floatValue); // Output: 42.5 + ``` + + *Hinglish Explanation:* `parseFloat()` function se string ko floating-point number me convert kiya jaata hai, aur decimal points bhi handle hota hai. + +### Number to String + +- **`String()` Function**: Converts a number to a string. + + ```javascript + let num = 42; + let str = String(num); // Converts 42 to '42' + console.log(str); // Output: '42' + ``` + + *Hinglish Explanation:* `String()` function se number ko string me convert kiya jaata hai. + +- **`toString()` Method**: Converts a number to a string. This is a method available on number variables. + + ```javascript + let num = 42; + let str = num.toString(); // Converts 42 to '42' + console.log(str); // Output: '42' + ``` + + *Hinglish Explanation:* `toString()` method bhi number ko string me convert karta hai, aur ye method number ke upar hota hai. + +### String to Boolean + +- **`Boolean()` Function**: Converts a string to a boolean. Non-empty strings become `true`, and an empty string becomes `false`. + + ```javascript + let nonEmptyStr = 'Hello'; + let emptyStr = ''; + console.log(Boolean(nonEmptyStr)); // Output: true + console.log(Boolean(emptyStr)); // Output: false + ``` + + *Hinglish Explanation:* `Boolean()` function se string ko boolean me convert kiya jaata hai. Non-empty string `true` ban jaati hai aur empty string `false` ban jaati hai. + +### Boolean to String + +- **`String()` Function**: Converts a boolean value to a string. + + ```javascript + let boolTrue = true; + let boolFalse = false; + console.log(String(boolTrue)); // Output: 'true' + console.log(String(boolFalse)); // Output: 'false' + ``` + + *Hinglish Explanation:* `String()` function se boolean ko string me convert kiya jaata hai. + +## Implicit Type Conversion + +**Implicit type conversion** happens automatically when JavaScript needs to convert between types in certain contexts. + +- **String Concatenation**: When you add a number to a string, JavaScript converts the number to a string and concatenates them. + + ```javascript + let result = 'The number is ' + 42; + console.log(result); // Output: 'The number is 42' + ``` + + *Hinglish Explanation:* Jab string ke saath number add karte hain, JavaScript number ko string me convert kar deta hai aur dono ko concatenate kar deta hai. + +- **Arithmetic Operations**: Subtracting a string from a number converts the string to a number. + + ```javascript + let result = 42 - '20'; + console.log(result); // Output: 22 + ``` + + *Hinglish Explanation:* Jab number se string ko subtract karte hain, JavaScript string ko number me convert kar deta hai aur phir subtraction karta hai. + +- **Unary Plus (`+`) Operator**: This operator is used to convert a string to a number. + + ```javascript + let str = '42'; + let num = +str; + console.log(num); // Output: 42 + ``` + + *Hinglish Explanation:* Unary plus (`+`) operator se string ko number me convert kar sakte hain. + +## Examples + +### Single File Example + +Create a file named `conversion.js` with the following content: + +```javascript +// String to Number +let strToNum = Number('42'); // Converts '42' to 42 +console.log('String to Number:', strToNum); + +// Number to String +let numToStr = String(42); // Converts 42 to '42' +console.log('Number to String:', numToStr); + +// String to Boolean +let strToBool = Boolean('Hello'); // Converts 'Hello' to true +console.log('String to Boolean:', strToBool); + +// Boolean to String +let boolToStr = String(true); // Converts true to 'true' +console.log('Boolean to String:', boolToStr); + +// Implicit Type Conversion +let implicitConcatenation = 'The number is ' + 42; // Concatenates string and number +console.log('Implicit Concatenation:', implicitConcatenation); + +let implicitSubtraction = 42 - '20'; // Converts '20' to 20 and subtracts +console.log('Implicit Subtraction:', implicitSubtraction); + +let unaryPlusConversion = +'42'; // Converts '42' to 42 +console.log('Unary Plus Conversion:', unaryPlusConversion); + +``` +# JavaScript Data Type Conversion + +## Overview + +In JavaScript, **data type conversion** refers to the process of changing a value from one type to another. JavaScript provides ways to convert types explicitly using functions, and it also performs automatic type conversion in certain situations. This guide will help you understand both explicit and implicit type conversion. + +## Explicit Type Conversion + +**Explicit type conversion** means manually converting a value from one type to another using JavaScript functions. + +### String to Number + +- **`Number()` Function**: Converts a string to a number. If the string contains non-numeric characters, it returns `NaN` (Not-a-Number). + + ```javascript + let str = '42'; + let num = Number(str); // Converts '42' to 42 + console.log(num); // Output: 42 + ``` + + *Hinglish Explanation:* `Number()` function se hum string ko number me convert kar sakte hain. Agar string mein numeric characters nahi hain, to `NaN` milta hai. + +- **`parseInt()` Function**: Converts a string to an integer. It parses the string until it encounters a non-numeric character. + + ```javascript + let str = '42px'; + let intValue = parseInt(str); // Converts '42px' to 42 + console.log(intValue); // Output: 42 + ``` + + *Hinglish Explanation:* `parseInt()` function se string ka integer part convert hota hai. Extra characters ko ignore kar deta hai. + +- **`parseFloat()` Function**: Converts a string to a floating-point number. It also parses until it hits a non-numeric character but handles decimal points. + + ```javascript + let str = '42.5abc'; + let floatValue = parseFloat(str); // Converts '42.5abc' to 42.5 + console.log(floatValue); // Output: 42.5 + ``` + + *Hinglish Explanation:* `parseFloat()` function se string ko floating-point number me convert kiya jaata hai, aur decimal points bhi handle hota hai. + +### Number to String + +- **`String()` Function**: Converts a number to a string. + + ```javascript + let num = 42; + let str = String(num); // Converts 42 to '42' + console.log(str); // Output: '42' + ``` + + *Hinglish Explanation:* `String()` function se number ko string me convert kiya jaata hai. + +- **`toString()` Method**: Converts a number to a string. This is a method available on number variables. + + ```javascript + let num = 42; + let str = num.toString(); // Converts 42 to '42' + console.log(str); // Output: '42' + ``` + + *Hinglish Explanation:* `toString()` method bhi number ko string me convert karta hai, aur ye method number ke upar hota hai. + +### String to Boolean + +- **`Boolean()` Function**: Converts a string to a boolean. Non-empty strings become `true`, and an empty string becomes `false`. + + ```javascript + let nonEmptyStr = 'Hello'; + let emptyStr = ''; + console.log(Boolean(nonEmptyStr)); // Output: true + console.log(Boolean(emptyStr)); // Output: false + ``` + + *Hinglish Explanation:* `Boolean()` function se string ko boolean me convert kiya jaata hai. Non-empty string `true` ban jaati hai aur empty string `false` ban jaati hai. + +### Boolean to String + +- **`String()` Function**: Converts a boolean value to a string. + + ```javascript + let boolTrue = true; + let boolFalse = false; + console.log(String(boolTrue)); // Output: 'true' + console.log(String(boolFalse)); // Output: 'false' + ``` + + *Hinglish Explanation:* `String()` function se boolean ko string me convert kiya jaata hai. + +## Implicit Type Conversion + +**Implicit type conversion** happens automatically when JavaScript needs to convert between types in certain contexts. + +- **String Concatenation**: When you add a number to a string, JavaScript converts the number to a string and concatenates them. + + ```javascript + let result = 'The number is ' + 42; + console.log(result); // Output: 'The number is 42' + ``` + + *Hinglish Explanation:* Jab string ke saath number add karte hain, JavaScript number ko string me convert kar deta hai aur dono ko concatenate kar deta hai. + +- **Arithmetic Operations**: Subtracting a string from a number converts the string to a number. + + ```javascript + let result = 42 - '20'; + console.log(result); // Output: 22 + ``` + + *Hinglish Explanation:* Jab number se string ko subtract karte hain, JavaScript string ko number me convert kar deta hai aur phir subtraction karta hai. + +- **Unary Plus (`+`) Operator**: This operator is used to convert a string to a number. + + ```javascript + let str = '42'; + let num = +str; + console.log(num); // Output: 42 + ``` + + *Hinglish Explanation:* Unary plus (`+`) operator se string ko number me convert kar sakte hain. + +## Examples + +### Single File Example + +Create a file named `conversion.js` with the following content: + +```javascript +// String to Number +let strToNum = Number('42'); // Converts '42' to 42 +console.log('String to Number:', strToNum); + +// Number to String +let numToStr = String(42); // Converts 42 to '42' +console.log('Number to String:', numToStr); + +// String to Boolean +let strToBool = Boolean('Hello'); // Converts 'Hello' to true +console.log('String to Boolean:', strToBool); + +// Boolean to String +let boolToStr = String(true); // Converts true to 'true' +console.log('Boolean to String:', boolToStr); + +// Implicit Type Conversion +let implicitConcatenation = 'The number is ' + 42; // Concatenates string and number +console.log('Implicit Concatenation:', implicitConcatenation); + +let implicitSubtraction = 42 - '20'; // Converts '20' to 20 and subtracts +console.log('Implicit Subtraction:', implicitSubtraction); + +let unaryPlusConversion = +'42'; // Converts '42' to 42 +console.log('Unary Plus Conversion:', unaryPlusConversion); + + +``` \ No newline at end of file diff --git a/JavaScript/08_Day_Data_Type_convert/started_code/script.js b/JavaScript/08_Day_Data_Type_convert/started_code/script.js new file mode 100644 index 0000000..62bd822 --- /dev/null +++ b/JavaScript/08_Day_Data_Type_convert/started_code/script.js @@ -0,0 +1,79 @@ +// We start with a variable named 'score' which holds a string value '33a'. +let score = '33a'; + +// Log the type of 'score' to the console. +// Expected output: 'string' +console.log(typeof(score)); // Output: string + +// Convert the 'score' variable from a string to a number using the Number() function. +// '33a' cannot be fully converted to a number because of the 'a', resulting in NaN. +let valueInNumber = Number(score); + +// Log the type of 'valueInNumber' to the console. +// Expected output: 'number' because the result is a number type, even though it is NaN. +console.log(typeof(valueInNumber)); // Output: number + +// Log the value of 'valueInNumber' to the console. +// Expected output: NaN +console.log(valueInNumber); // Output: NaN + + +// Using parseInt() to convert a string to an integer.? +// parseInt() will ignore trailing non-numeric characters and convert the initial numeric part. +let parsedIntValue = parseInt('33a'); // '33a' will be converted to 33 +console.log(typeof(parsedIntValue)); // Expected output: 'number' +console.log(parsedIntValue); // Output: 33 + +// Using parseFloat() to convert a string to a floating-point number. +// parseFloat() will convert the initial numeric part of the string and ignore trailing non-numeric characters. +let parsedFloatValue = parseFloat('33.5abc'); // '33.5abc' will be converted to 33.5 +console.log(typeof(parsedFloatValue)); // Expected output: 'number' +console.log(parsedFloatValue); // Output: 33.5 + +// Converting a boolean to a number using Number() function. +let booleanTrue = true; +let booleanFalse = false; +console.log(Number(booleanTrue)); // Output: 1 (true) +console.log(Number(booleanFalse)); // Output: 0 (false) + + + +// Converting a number to a string using String() function. +let number = 42; +let numberToString = String(number); +console.log(typeof(numberToString)); // Expected output: 'string' +console.log(numberToString); // Output: '42' + +// Converting a boolean to a string using String() function. +let booleanToStringTrue = String(true); +let booleanToStringFalse = String(false); +console.log(typeof(booleanToStringTrue)); // Expected output: 'string' +console.log(booleanToStringTrue); // Output: 'true' +console.log(typeof(booleanToStringFalse)); // Expected output: 'string' +console.log(booleanToStringFalse); // Output: 'false' + +// Implicit type conversion (type coercion) examples: +// Adding a number to a string results in string concatenation. +let concatenatedResult = 'The answer is ' + 42; +console.log(concatenatedResult); // Output: 'The answer is 42' + +// Subtracting a string from a number attempts to convert the string to a number. +let subtractionResult = 42 - '20'; +console.log(subtractionResult); // Output: 22 + +// Using unary plus (+) operator to convert a string to a number. +// This operator attempts to convert the operand to a number. +let unaryPlusResult = +'42'; +console.log(typeof(unaryPlusResult)); // Expected output: 'number' +console.log(unaryPlusResult); // Output: 42 + +// Example of explicit type conversion using Boolean() function. +// Converting various values to boolean. +console.log(Boolean(0)); // Output: false (0 is falsy) +console.log(Boolean(1)); // Output: true (non-zero numbers are truthy) +console.log(Boolean('')); // Output: false (empty string is falsy) +console.log(Boolean('Hello')); // Output: true (non-empty string is truthy) +console.log(Boolean(null)); // Output: false (null is falsy) +console.log(Boolean(undefined)); // Output: false (undefined is falsy) +console.log(Boolean([])); // Output: true (empty array is truthy) +console.log(Boolean({})); // Output: true (empty object is truthy) diff --git a/JavaScript/08_Day_JavaScript Operators/started_code/script.js b/JavaScript/08_Day_JavaScript Operators/started_code/script.js new file mode 100644 index 0000000..6b4c619 --- /dev/null +++ b/JavaScript/08_Day_JavaScript Operators/started_code/script.js @@ -0,0 +1,55 @@ + +/****************************************************************************************************** +// TODO JAVASCRIPT OPERATORS * +* OPERATORS ARE USED TO PERFORM DIFFERENT TYPES OF MATHEMATICAL AND LOGICAL COMPUTATIONS. * +// ? EXAMPLES: * + * THE ASSIGNMENT OPERATOR = ASSIGNS VALUES * + * THE ADDITION OPERATOR + ADDS VALUES * + * THE MULTIPLICATION OPERATOR * MULTIPLIES VALUES * + * THE COMPARISON OPERATOR > COMPARES VALUES * + ******************************************************************************************************/ + + + +/* -------------------------------------------------------------------------- */ +/* Arithmetic Operators */ +/* -------------------------------------------------------------------------- */ + +//* 1. Addition + +// The + operator is used Add two numbers and concatenation two String together. + +// ? Add num1 and num2 together +let num1 = 1; +let num2 = 3; + +console.log(`Add two different number Together (${num1} + ${num2}):-` , num1 + num2) // Output: 3 + + +// ? Add str1 and str2 together + + +let str1 = "Hello"; +let str2 = "World"; + +// Two String ko add kr ne ko bolte hain string Concatenation +console.log(`Concatenate two strings (${str1} + ${str2}) :-` , str1 + " "+str2) // Output: "Hello World" + + +// ? Add Number and String +let num = 10; +let str = "apples"; +console.log(`Add number to string(${num} + ${str}) :-`, num + str); // Output: "10 apples" + + +// ? Adding Boolean Values (true + true) +let bool1 = true; +let bool2 = true; +console.log("`Add boolean values (true + true):", bool1 + bool2); // Output: 2 (true is treated as 1, so 1 + 1 = 2) + + +// ? Adding Boolean Values (true + false) +let bool3 = true; +let bool4 = false; +console.log("Add boolean values (true + false):", bool3 + bool4); // Output: 2 (true is treated as 1 and false is treated 0, so 1 + 0 = 1) + diff --git a/JavaScript/this/readme.md b/JavaScript/this/readme.md new file mode 100644 index 0000000..215a3a1 --- /dev/null +++ b/JavaScript/this/readme.md @@ -0,0 +1 @@ +# this Keyword \ No newline at end of file