{"data":{"current_page":1,"data":[{"id":12,"user_id":1,"category_id":2,"title":"How to Deploy a React Native App to Google Play Store (Step-by-Step Guide)","slug":"how-to-deploy-react-native-app-google-play-store","content":"{\"time\":1785992573594,\"blocks\":[{\"id\":\"W4F9j9_OW7\",\"type\":\"header\",\"data\":{\"text\":\"How to Deploy a React Native App to Google Play Store (Step-by-Step Guide)\",\"level\":2}},{\"id\":\"Ajk321fb3Y\",\"type\":\"paragraph\",\"data\":{\"text\":\"Publishing your first React Native app to the Google Play Store can feel like navigating a maze. You have built your screens, hooked up your APIs, and tested everything locally. But now comes the actual hurdle: turning your local JavaScript and native code into a production-ready package that Google accepts without throwing cryptically worded errors.\"}},{\"id\":\"DM5lIXi4-t\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you are feeling overwhelmed by terms like keystores, AAB files, app signing, and release tracks\u2014don't worry. I have been through this exact process dozens of times.\"}},{\"id\":\"LCLsug5ZV1\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this guide, I will take you through the entire deployment journey from scratch. We will start right from generating your release keystore in the terminal, configure your Android project files, create your Google Play Console account, and finally roll out your app to production.\"}},{\"id\":\"RRFswEsRYV\",\"type\":\"paragraph\",\"data\":{\"text\":\"Grab a cup of coffee, open your terminal, and let\u2019s get your app into the hands of real users!\"}},{\"id\":\"PKEsG_sBWT\",\"type\":\"header\",\"data\":{\"text\":\"Pre-Requisites Checklist\",\"level\":2}},{\"id\":\"7mVN4cd1PK\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before we start typing commands, make sure you have:\"}},{\"id\":\"_obd13xkuC\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"A working <b>React Native project<\/b> tested on an Android emulator or physical device.\",\"<b>Node.js<\/b>, <b>JDK (Java Development Kit)<\/b>, and <b>Android Studio<\/b> properly installed on your machine.\",\"A <b>Google Play Developer Account<\/b> ($25 one-time registration fee required by Google).\",\"Essential assets ready: <b>App Icon<\/b> (512x512 px) and at least <b>2-3 Feature Screenshots<\/b>.\"]}},{\"id\":\"y7OLx_XWAi\",\"type\":\"header\",\"data\":{\"text\":\"Step 1: Generate an Android Release Keystore\",\"level\":2}},{\"id\":\"vErTlY_ty2\",\"type\":\"paragraph\",\"data\":{\"text\":\"To publish an application on the Google Play Store, Google requires every Android app to be digitally signed with a private certificate. This keystore acts as your digital identity.\"}},{\"id\":\"IE2wx8VqQj\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>CRITICAL NOTE:<\/b> Keep your keystore file and its passwords extremely safe! If you lose this key, you will <b>never<\/b> be able to update your application on the Play Store again.\"}},{\"id\":\"1EsBHTf3Lw\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open your terminal, navigate to your root directory, and run the following command using the <code>keytool<\/code> utility provided by JDK:\"}},{\"id\":\"48XQ2olPuk\",\"type\":\"paragraph\",\"data\":{\"text\":\"Bash\"}},{\"id\":\"gSMlG4d6OD\",\"type\":\"code\",\"data\":{\"code\":\"keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000\\n\"}},{\"id\":\"Sfz68dclfi\",\"type\":\"header\",\"data\":{\"text\":\"What happens when you run this?\",\"level\":3}},{\"id\":\"XDwan_qUVJ\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"It will prompt you to enter a <b>keystore password<\/b> (choose a strong password and save it in your password manager).\",\"It will ask for personal details like First and Last Name, Organization, City, State, and Country Code (e.g., <code>IN<\/code> or <code>US<\/code>).\",\"Type <code>yes<\/code> to confirm the details.\"]}},{\"id\":\"iaQ6-nUiXF\",\"type\":\"paragraph\",\"data\":{\"text\":\"This command generates a file named <code>my-upload-key.keystore<\/code>.\"}},{\"id\":\"fPorLePOPl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Move this generated keystore file into your project\u2019s <code>android\/app<\/code> directory:\"}},{\"id\":\"0hm9Bw8AXi\",\"type\":\"paragraph\",\"data\":{\"text\":\"Bash\"}},{\"id\":\"vgCVkMIvJB\",\"type\":\"code\",\"data\":{\"code\":\"# Move keystore to android\/app directory\\nmv my-upload-key.keystore android\/app\/\\n\"}},{\"id\":\"1O_5C8pEOe\",\"type\":\"header\",\"data\":{\"text\":\"Step 2: Configure Gradle Variables in React Native\",\"level\":2}},{\"id\":\"dZjXxE7QLI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now that your keystore file is sitting inside <code>android\/app\/<\/code>, we need to tell Android\u2019s build system (Gradle) how to use it without committing passwords to GitHub or version control.\"}},{\"id\":\"tZnQk06ly4\",\"type\":\"header\",\"data\":{\"text\":\"1. Edit <code>android\/gradle.properties<\/code>\",\"level\":3}},{\"id\":\"R2tMliCV6y\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open <code>android\/gradle.properties<\/code> in your code editor and add the following lines at the bottom:\"}},{\"id\":\"pKqr0J3KJL\",\"type\":\"paragraph\",\"data\":{\"text\":\"Properties\"}},{\"id\":\"93xYCiviZ8\",\"type\":\"code\",\"data\":{\"code\":\"MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore\\nMYAPP_UPLOAD_KEY_ALIAS=my-key-alias\\nMYAPP_UPLOAD_STORE_PASSWORD=YourChosenStorePassword\\nMYAPP_UPLOAD_KEY_PASSWORD=YourChosenKeyPassword\\n\"}},{\"id\":\"is1_QIIV-i\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>(Replace <code>YourChosenStorePassword<\/code> and <code>YourChosenKeyPassword<\/code> with the actual password you created in Step 1).<\/i>\"}},{\"id\":\"spk2B7DFQs\",\"type\":\"header\",\"data\":{\"text\":\"2. Edit <code>android\/app\/build.gradle<\/code>\",\"level\":3}},{\"id\":\"7ORai-241s\",\"type\":\"paragraph\",\"data\":{\"text\":\"Next, open <code>android\/app\/build.gradle<\/code> (make sure it is the file inside the <code>app<\/code> folder, not the root <code>android<\/code> folder) and update the <code>signingConfigs<\/code> and <code>buildTypes<\/code> blocks:\"}},{\"id\":\"fj6c8fRN_k\",\"type\":\"paragraph\",\"data\":{\"text\":\"Groovy\"}},{\"id\":\"_BScUDxwPV\",\"type\":\"code\",\"data\":{\"code\":\"android {\\n    ...\\n    defaultConfig {\\n        applicationId \\\"com.yourcompany.yourappname\\\" \/\/ Make sure this is unique!\\n        minSdkVersion rootProject.ext.minSdkVersion\\n        targetSdkVersion rootProject.ext.targetSdkVersion\\n        versionCode 1\\n        versionName \\\"1.0.0\\\"\\n    }\\n\\n    signingConfigs {\\n        debug {\\n            storeFile file('debug.keystore')\\n            storePassword 'android'\\n            keyAlias 'androiddebugkey'\\n            keyPassword 'android'\\n        }\\n        release {\\n            if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) {\\n                storeFile file(MYAPP_UPLOAD_STORE_FILE)\\n                storePassword MYAPP_UPLOAD_STORE_PASSWORD\\n                keyAlias MYAPP_UPLOAD_KEY_ALIAS\\n                keyPassword MYAPP_UPLOAD_KEY_PASSWORD\\n            }\\n        }\\n    }\\n\\n    buildTypes {\\n        release {\\n            signingConfig signingConfigs.release\\n            minifyEnabled true\\n            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\\n        }\\n    }\\n}\\n\"}},{\"id\":\"6s8YzPIaoP\",\"type\":\"header\",\"data\":{\"text\":\"Step 3: Generate the Release Android App Bundle (AAB)\",\"level\":2}},{\"id\":\"0BnnYCLbjO\",\"type\":\"paragraph\",\"data\":{\"text\":\"Google Play Store now requires all new apps to be submitted in the <b>Android App Bundle (.aab)<\/b> format instead of the old <code>.apk<\/code> format. An <code>.aab<\/code> file allows Google Play to generate optimized APKs tailored specifically to each user\u2019s device architecture, reducing app download sizes.\"}},{\"id\":\"F3aINkndq3\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open your terminal, navigate to the <code>android<\/code> folder of your project, and clean old builds before bundling:\"}},{\"id\":\"QsDwt2DehX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Bash\"}},{\"id\":\"kegUtnNKKm\",\"type\":\"code\",\"data\":{\"code\":\"# Step into android directory\\ncd android\\n\\n# Clean existing build caches\\n.\/gradlew clean\\n\\n# Generate the release AAB bundle\\n.\/gradlew bundleRelease\\n\"}},{\"id\":\"kNABmDM59J\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>(On Windows, run <code>gradlew bundleRelease<\/code> without <code>.\/<\/code>)<\/i>\"}},{\"id\":\"9zAxBGAzx1\",\"type\":\"header\",\"data\":{\"text\":\"Where is my generated <code>.aab<\/code> file located?\",\"level\":3}},{\"id\":\"mT1aRR9Y9d\",\"type\":\"paragraph\",\"data\":{\"text\":\"Once the build completes successfully (you will see <code>BUILD SUCCESSFUL<\/code> in green text), your final bundle file will be waiting for you here:\"}},{\"id\":\"xR4SFw3omp\",\"type\":\"paragraph\",\"data\":{\"text\":\"Plaintext\"}},{\"id\":\"jaFtyte5XE\",\"type\":\"code\",\"data\":{\"code\":\"your-project\/android\/app\/build\/outputs\/bundle\/release\/app-release.aab\\n\"}},{\"id\":\"qNlUYkf-SI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Copy this <code>app-release.aab<\/code> file to your desktop or an easily accessible folder.\"}},{\"id\":\"kgDIQVI2Zj\",\"type\":\"header\",\"data\":{\"text\":\"Step 4: Create &amp; Setup Google Play Console Account\",\"level\":2}},{\"id\":\"_SlZR8UDh-\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you haven't already, head over to the <a target=\\\"_blank\\\" href=\\\"https:\/\/play.google.com\/console\/signup\\\">Google Play Console Registration Page<\/a> and log in with your developer Google account.\"}},{\"id\":\"ylyI1rVaof\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Pay the one-time <b>$25 developer registration fee<\/b>.\",\"Complete your developer profile details (Developer Name, Email, Phone Number).\",\"Verify your identity as requested by Google.\"]}},{\"id\":\"64oXaiEv6w\",\"type\":\"paragraph\",\"data\":{\"text\":\"Once logged into your dashboard, click the prominent <b>\\\"Create app\\\"<\/b> button at the top right corner.\"}},{\"id\":\"SGNYqsgOPE\",\"type\":\"header\",\"data\":{\"text\":\"App Setup Form Details:\",\"level\":3}},{\"id\":\"JVg2PPTmbu\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>App name:<\/b> Enter your app's public name (up to 30 characters).\",\"<b>Default language:<\/b> Choose your primary language (e.g., <i>English - US<\/i>).\",\"<b>App or Game:<\/b> Select <i>App<\/i>.\",\"<b>Free or Paid:<\/b> Select <i>Free<\/i> (Note: You cannot change a free app to paid later without creating a new app listing!).\",\"<b>Declarations:<\/b> Accept the Developer Program Policies and US export laws checkboxes.\",\"Click <b>Create app<\/b>.\"]}},{\"id\":\"1lrVVchp3-\",\"type\":\"header\",\"data\":{\"text\":\"Step 5: Complete Main Store Listing &amp; Policy Questionnaire\",\"level\":2}},{\"id\":\"nzltp818kI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Google requires all developers to answer safety and content questions before releasing an app. In your Play Console sidebar, scroll down to the <b>\\\"App content\\\"<\/b> section under <i>Policy<\/i>.\"}},{\"id\":\"32PySFU5x1\",\"type\":\"paragraph\",\"data\":{\"text\":\"You must complete all mandatory sections:\"}},{\"id\":\"4ZVNYO8J72\",\"type\":\"header\",\"data\":{\"text\":\"1. Privacy Policy\",\"level\":3}},{\"id\":\"bJU5pa9MZL\",\"type\":\"paragraph\",\"data\":{\"text\":\"Provide a working HTTPS link to your app's privacy policy web page. (You can generate free privacy policies using tools like App Privacy Policy Generator).\"}},{\"id\":\"RpgzMk4hUh\",\"type\":\"header\",\"data\":{\"text\":\"2. Ads\",\"level\":3}},{\"id\":\"jIUNv3M4jr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Declare whether your app contains advertisements (AdMob, Meta Audience Network, etc.).\"}},{\"id\":\"t53rna1osq\",\"type\":\"header\",\"data\":{\"text\":\"3. App Access\",\"level\":3}},{\"id\":\"immHy7zhb_\",\"type\":\"paragraph\",\"data\":{\"text\":\"If your app requires user login, you must provide Google reviewers with a working test username and password so they can log in and review your app screens.\"}},{\"id\":\"wj3yEggOHl\",\"type\":\"header\",\"data\":{\"text\":\"4. Content Ratings\",\"level\":3}},{\"id\":\"JMuyf81K8S\",\"type\":\"paragraph\",\"data\":{\"text\":\"Fill out a questionnaire about your app's content (gambling, violence, social interaction). Google will automatically calculate your age rating certification based on your responses.\"}},{\"id\":\"kOo-W_yRyA\",\"type\":\"header\",\"data\":{\"text\":\"5. Target Audience\",\"level\":3}},{\"id\":\"e9eP3xTtPU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Specify the primary age group for your application. If your app targets children under 13, you must comply with strict COPPA guidelines.\"}},{\"id\":\"VlTUyC--43\",\"type\":\"header\",\"data\":{\"text\":\"6. Data Safety Section\",\"level\":3}},{\"id\":\"KvbatXJ4tU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Declare what types of data your app collects (e.g., location, email address, device IDs) and whether data is encrypted in transit.\"}},{\"id\":\"tPK2re8d8S\",\"type\":\"header\",\"data\":{\"text\":\"Step 6: Set Up Your Main Store Listing Assets\",\"level\":2}},{\"id\":\"AJvMqeCwHq\",\"type\":\"paragraph\",\"data\":{\"text\":\"Next, go to <b>\\\"Main store listing\\\"<\/b> under the <i>Grow<\/i> section on the left navigation drawer. This is what users will see when they browse your app on the Play Store.\"}},{\"id\":\"mhgIJiC_B_\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Short description:<\/b> Summarize your app in 80 characters or fewer.\",\"<b>Full description:<\/b> Detailed description highlighting core features and value props (up to 4,000 characters).\",\"<b>App icon:<\/b> Upload a transparent PNG\/JPEG matching <b>512 x 512 pixels<\/b> (Max size 1 MB).\",\"<b>Feature graphic:<\/b> Upload a promo banner matching <b>1024 x 500 pixels<\/b> (JPEG\/24-bit PNG).\",\"<b>Phone Screenshots:<\/b> Upload at least 2 to 8 screenshots of your running app. Aspect ratio must be 16:9 or 9:16 (minimum 320px, max 3840px per side).\"]}},{\"id\":\"PGKPL9Muy2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Click <b>Save<\/b> at the bottom of the page.\"}},{\"id\":\"-1c1Bldga9\",\"type\":\"header\",\"data\":{\"text\":\"Step 7: Create a Production Release &amp; Upload <code>.aab<\/code>\",\"level\":2}},{\"id\":\"PyqMvdZ1ij\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now comes the exciting part\u2014uploading your React Native bundle!\"}},{\"id\":\"h6z437Sef6\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"In the left-hand menu, navigate to <b>Testing &amp; release<\/b> $\\\\rightarrow$ <b>Production<\/b>.\",\"Click on <b>\\\"Create new release\\\"<\/b> at the top right.\",\"Google Play will ask if you want to use <b>Google Play App Signing<\/b>. Click <b>\\\"Choose signing key\\\"<\/b> or accept the default setting (Google automatically handles your app signing key securely).\",\"Under <b>App bundles<\/b>, click <b>Upload<\/b> and select your <code>app-release.aab<\/code> file from Step 3.\",\"Wait for the upload progress bar to hit 100%. Play Console will analyze your bundle and extract version numbers automatically.\",\"Under <b>Release details<\/b>, enter your release name (e.g., <code>1.0.0<\/code>) and enter your <b>Release notes<\/b> (e.g., <i>\\\"Initial release of our mobile application featuring user authentication, catalog browsing, and instant checkout!\\\"<\/i>).\",\"Click <b>Save<\/b>, then click <b>Next<\/b> \/ <b>Review release<\/b>.\"]}},{\"id\":\"RfTWVEgwVd\",\"type\":\"header\",\"data\":{\"text\":\"Step 8: Review and Rollout to Production\",\"level\":2}},{\"id\":\"eAp9CtXOKO\",\"type\":\"paragraph\",\"data\":{\"text\":\"If there are any errors in your build configuration, Google Play Console will display red error badges explaining what needs fixing. If everything was configured correctly following this guide, you will only see minor blue information warnings.\"}},{\"id\":\"GA7t7cogvv\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Click <b>\\\"Start rollout to Production\\\"<\/b>.\",\"Confirm the rollout modal pop-up.\"]}},{\"id\":\"sFarqDIyBE\",\"type\":\"header\",\"data\":{\"text\":\"What Happens Next? (Review Timelines)\",\"level\":2}},{\"id\":\"NdSUW6XK4x\",\"type\":\"paragraph\",\"data\":{\"text\":\"Congratulations! Your React Native app is officially submitted to Google Play.\"}},{\"id\":\"IrdPrvQFfB\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>First-time Publisher Review:<\/b> New Google Play developer accounts usually undergo a manual review process that takes anywhere from <b>3 to 7 days<\/b>.\",\"<b>Subsequent Updates:<\/b> Future updates typically get approved in under 24 hours.\"]}},{\"id\":\"vJKEtnIB81\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can check the status anytime under the <b>Overview<\/b> dashboard in Play Console:\"}},{\"id\":\"OPQ_29mBHj\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>In review<\/code> = Google\u2019s automated system and human reviewers are checking your app.\",\"<code>Approved<\/code> \/ <code>Published<\/code> = Your app is live on the Play Store globally!\"]}},{\"id\":\"qF2jpLExB9\",\"type\":\"header\",\"data\":{\"text\":\"Pro-Tips for React Native Production Maintenance\",\"level\":2}},{\"id\":\"-nE-98jAu2\",\"type\":\"paragraph\",\"data\":{\"text\":\"To avoid unexpected app store rejection or runtime crashes after release:\"}},{\"id\":\"6P127Ru_Bw\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Increment Version Numbers:<\/b> Every time you upload a new bundle to Play Console, you <b>MUST<\/b> increment the <code>versionCode<\/code> in <code>android\/app\/build.gradle<\/code> (e.g., from <code>1<\/code> to <code>2<\/code>).\",\"<b>Enable ProGuard Rules:<\/b> If your app crashes immediately after downloading from the Play Store, check your ProGuard configuration in <code>android\/app\/proguard-rules.pro<\/code>. Third-party packages often need specific keep-rules to prevent code obfuscation bugs.\",\"<b>Test with Internal Testing Tracks:<\/b> Before pushing directly to Production, upload your <code>.aab<\/code> to Play Console\u2019s <b>Internal Testing<\/b> or <b>Closed Beta<\/b> track first. Send invitation links to team members to verify real-world performance on physical devices.\"]}},{\"id\":\"jL0GDvavrY\",\"type\":\"header\",\"data\":{\"text\":\"<b>Conclusion<\/b>\",\"level\":2}},{\"id\":\"XS6VTcxCfk\",\"type\":\"paragraph\",\"data\":{\"text\":\"Deploying a React Native application to the Google Play Store is a vital skill for modern mobile developers. By carefully generating a secure keystore, configuring Gradle variables, building an optimized <code>.aab<\/code> bundle, and keeping your store metadata updated, you ensure a smooth deployment cycle every single time.\"}},{\"id\":\"Pv4bMmWwiR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Keep your keystore file backed up securely, monitor your Play Console vitals for crash logs post-launch, and keep building awesome apps!\"}},{\"id\":\"i5XV3J3EPE\",\"type\":\"paragraph\",\"data\":{\"text\":\"Related Link Here:\"}},{\"id\":\"KcqCDXBF6K\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/fix-stripe-sdk-crash-react-native-android-ios\\\">How to Fix Stripe SDK Crashes in React Native (Android &amp; iOS Complete Guide)<\/a>\",\"level\":3}},{\"id\":\"UrvH_7Af8F\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/how-to-handle-multiple-input-fields-react-usestate\\\">How to Handle Multiple Input Fields in React with useState (Clean Code Guide)<\/a>\",\"level\":3}},{\"id\":\"mn2tYJQM8I\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/build-google-keep-clone-react-class-components\\\">How to Build a Google Keep Clone with React.js (Class Components)<\/a>\",\"level\":3}},{\"id\":\"SUTvYO49T4\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/build-a-dynamic-e-commerce-shopping-cart-with-react-and-vite-a-beginners-guide\\\">How to Build a Dynamic E-Commerce Shopping Cart with React and Vite: A Complete Beginner's Guide<\/a>\",\"level\":4}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/how-to-deploy-react-native-app-google-play-store-1785992611.jfif","status":"published","excerpt":"Step-by-step tutorial on how to build, sign, and publish your React Native app to the Google Play Store. Commands, Play Console setup, and release tips included.","published_at":"2026-08-06T05:02:53.594000Z","tags":"[\"deploy react native\",\"app to play store\",\"react native\",\"react js\",\"hooks\",\"android development\",\"ios development\",\"react native developer\"]","created_at":"2026-08-06T05:03:31.000000Z","updated_at":"2026-11-27T12:05:18.000000Z","views":24,"scheduled_at":null,"seo":{"id":20,"seoable_type":"App\\Models\\Blog","seoable_id":12,"meta_title":"How to Deploy a React Native App to Google Play Store (Step-by-Step Guide) | SamWithCode","meta_description":"Step-by-step tutorial on how to build, sign, and publish your React Native app to the Google Play Store. Commands, Play Console setup, and release tips included.","meta_keywords":"publish react native app google play, generate android signed bundle react native, react native play console setup, react native upload AAB file,deploy react native app to play store","meta_image":"seo\/how-to-deploy-react-native-app-google-play-store-1785992611.jfif","og_title":"How to Deploy a React Native App to Google Play Store (Step-by-Step Guide) | SamWithCode","og_description":"Step-by-step tutorial on how to build, sign, and publish your React Native app to the Google Play Store. Commands, Play Console setup, and release tips included.","og_image":"seo\/how-to-deploy-react-native-app-google-play-store-1785992611.jfif","extra":null,"created_at":"2026-08-06T05:03:31.000000Z","updated_at":"2026-08-06T05:03:31.000000Z"},"category":{"id":2,"name":"Web Development","slug":"web-development","created_at":"2026-07-05T12:39:07.000000Z","updated_at":"2026-07-05T12:39:07.000000Z"}},{"id":11,"user_id":1,"category_id":2,"title":"How to Fix Stripe SDK Crashes in React Native (Android & iOS Complete Guide)","slug":"fix-stripe-sdk-crash-react-native-android-ios","content":"{\"time\":1785870855846,\"blocks\":[{\"id\":\"QmV_kaWt2L\",\"type\":\"header\",\"data\":{\"text\":\"How to Fix Stripe SDK Crashes in React Native (Android &amp; iOS Complete Guide)\",\"level\":2}},{\"id\":\"WQvcF7kkKf\",\"type\":\"paragraph\",\"data\":{\"text\":\"There is almost nothing worse in mobile app development than having your checkout flow crash right in front of a paying customer. You have spent weeks perfecting your UI, integrating backend APIs, and setting up products, only for the app to instantly close the moment a user taps <b>\\\"Pay Now\\\"<\/b>.\"}},{\"id\":\"6YVDNFPNCk\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you are using <code>@stripe\/stripe-react-native<\/code>, app crashes on iOS and Android are rarely caused by basic JavaScript bugs. Instead, they almost always stem from native library mismatches, missing Android Material themes, outdated CocoaPods, or unhandled asynchronous promise rejections.\"}},{\"id\":\"kU-TtyyFU3\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this practical, code-first tutorial, we will break down why <code>@stripe\/stripe-react-native<\/code> crashes on both Android and iOS, and walk through the exact steps and native code fixes required to make your payment flow crash-proof.\"}},{\"id\":\"lw8i-zmtCb\",\"type\":\"header\",\"data\":{\"text\":\"Why <code>@stripe\/stripe-react-native<\/code> Crashes in Production\",\"level\":2}},{\"id\":\"7Xm9jVBD1L\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because React Native relies on native bridges to talk to native iOS (Swift\/Objective-C) and Android (Kotlin\/Java) SDKs, any mismatch at the native level causes a fatal runtime crash.\"}},{\"id\":\"pIpOP2HjQS\",\"type\":\"paragraph\",\"data\":{\"text\":\"The top reasons for Stripe SDK crashes in React Native include:\"}},{\"id\":\"tyHVwNlJDC\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Missing Android Material Theme:<\/b> Stripe\u2019s Android UI components require a <code>MaterialComponents<\/code> theme parent.\",\"<b>Outdated CocoaPods &amp; Podfile Mismatches (iOS):<\/b> Incompatible deployment targets or cached build artifacts.\",\"<b>Unchecked Client Secrets:<\/b> Initialising <code>initPaymentSheet()<\/code> with an <code>undefined<\/code> or <code>null<\/code> secret from an unhandled backend error.\",\"<b>React Native New Architecture &amp; Gradle Incompatibilities:<\/b> Version mismatches between Kotlin, Gradle, and <code>@stripe\/stripe-react-native<\/code>.\"]}},{\"id\":\"U6BXNCd950\",\"type\":\"header\",\"data\":{\"text\":\"1. Fixing Android Crashes: <code>Theme.MaterialComponents<\/code> Requirement\",\"level\":2}},{\"id\":\"xg07TJ3UeU\",\"type\":\"header\",\"data\":{\"text\":\"The Bug\",\"level\":3}},{\"id\":\"uaCOyfasav\",\"type\":\"paragraph\",\"data\":{\"text\":\"On Android devices or emulators, tapping the payment button triggers an immediate crash, outputting the following native log in Logcat:\"}},{\"id\":\"06KyYXmIMM\",\"type\":\"paragraph\",\"data\":{\"text\":\"Plaintext\"}},{\"id\":\"N8EUWfmVwH\",\"type\":\"code\",\"data\":{\"code\":\"java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).\\n\"}},{\"id\":\"TC3KZAokYy\",\"type\":\"header\",\"data\":{\"text\":\"The Practical Solution\",\"level\":3}},{\"id\":\"UhJxueLv9f\",\"type\":\"paragraph\",\"data\":{\"text\":\"Stripe\u2019s Android Native SDK uses Google Material components for its PaymentSheet UI. If your React Native app uses a basic <code>AppCompat<\/code> or default system theme, Android throws an <code>IllegalArgumentException<\/code>.\"}},{\"id\":\"JplVO8vrrO\",\"type\":\"header\",\"data\":{\"text\":\"Step 1: Update <code>styles.xml<\/code>\",\"level\":4}},{\"id\":\"El3KeNj7g1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Navigate to <code>android\/app\/src\/main\/res\/values\/styles.xml<\/code> in your React Native project and change your <code>AppTheme<\/code> parent:\"}},{\"id\":\"6qia4tjgwn\",\"type\":\"paragraph\",\"data\":{\"text\":\"XML\"}},{\"id\":\"BWY68IW6cR\",\"type\":\"code\",\"data\":{\"code\":\"<resources>\\n    <!-- Base application theme. -->\\n    <style name=\\\"AppTheme\\\" parent=\\\"Theme.MaterialComponents.DayNight.NoActionBar\\\">\\n        <!-- Customize your primary colors here -->\\n        <item name=\\\"colorPrimary\\\">@color\/colorPrimary<\/item>\\n        <item name=\\\"colorPrimaryDark\\\">@color\/colorPrimaryDark<\/item>\\n        <item name=\\\"colorAccent\\\">@color\/colorAccent<\/item>\\n    <\/style>\\n<\/resources>\\n\"}},{\"id\":\"dCee63jI5G\",\"type\":\"header\",\"data\":{\"text\":\"Step 2: Ensure Modern Gradle &amp; Kotlin Versions\",\"level\":4}},{\"id\":\"-36iLXBNJu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Verify your top-level <code>android\/build.gradle<\/code> file matches the required Kotlin and Gradle configurations for modern Stripe releases:\"}},{\"id\":\"53Bp_SGtAJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Groovy\"}},{\"id\":\"wEIkMcAFeE\",\"type\":\"code\",\"data\":{\"code\":\"buildscript {\\n    ext {\\n        buildToolsVersion = \\\"34.0.0\\\"\\n        minSdkVersion = 21\\n        compileSdkVersion = 34\\n        targetSdkVersion = 34\\n        kotlinVersion = \\\"1.9.22\\\"\\n    }\\n    dependencies {\\n        classpath(\\\"com.android.tools.build:gradle:8.2.1\\\")\\n        classpath(\\\"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion\\\")\\n    }\\n}\\n\"}},{\"id\":\"A2OzlmjLMK\",\"type\":\"header\",\"data\":{\"text\":\"2. Fixing iOS Crashes: CocoaPods &amp; Deployment Target Mismatches\",\"level\":2}},{\"id\":\"KQLh3t6iVW\",\"type\":\"header\",\"data\":{\"text\":\"The Bug\",\"level\":3}},{\"id\":\"aZy1iD9SmK\",\"type\":\"paragraph\",\"data\":{\"text\":\"On iOS, the app either fails during <code>npx react-native run-ios<\/code> \/ Xcode archive, or crashes instantly upon opening the PaymentSheet with <code>Dyld Error: Symbol not found<\/code> or <code>Module 'Stripe' not found<\/code>.\"}},{\"id\":\"xt100d7cF2\",\"type\":\"header\",\"data\":{\"text\":\"The Practical Solution\",\"level\":3}},{\"id\":\"VUlRXmc1v9\",\"type\":\"paragraph\",\"data\":{\"text\":\"Recent releases of <code>@stripe\/stripe-react-native<\/code> require a minimum deployment target of <b>iOS 13.0<\/b> (or higher).\"}},{\"id\":\"mRaS-tmUzi\",\"type\":\"header\",\"data\":{\"text\":\"Step 1: Update your <code>ios\/Podfile<\/code>\",\"level\":4}},{\"id\":\"_-KO2pi4mm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open <code>ios\/Podfile<\/code> and explicitly enforce the deployment target across all target Pods:\"}},{\"id\":\"uU6DTgKUe4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Ruby\"}},{\"id\":\"eoxyf2Ceaf\",\"type\":\"code\",\"data\":{\"code\":\"platform :ios, '13.0'\\n\\ntarget 'YourProjectName' do\\n  config = use_native_modules!\\n\\n  # Enable static framework linkage if using modern RN versions\\n  use_frameworks! :linkage => :static\\n\\n  flags = get_default_flags()\\n\\n  use_react_native!(\\n    :path => config[:reactNativePath],\\n    :hermes_enabled => flags[:hermes_enabled],\\n    :fabric_enabled => flags[:fabric_enabled],\\n  )\\n\\n  post_install do |installer|\\n    react_native_post_install(\\n      installer,\\n      config[:reactNativePath],\\n      :mac_catalyst_enabled => false\\n    )\\n    \\n    # Enforce iOS 13.0 for all CocoaPods sub-targets\\n    installer.pods_project.targets.each do |target|\\n      target.build_configurations.each do |config|\\n        config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'\\n      end\\n    end\\n  end\\nend\\n\"}},{\"id\":\"t4wRXpowT7\",\"type\":\"header\",\"data\":{\"text\":\"Step 2: Clean and Re-install Pods\",\"level\":4}},{\"id\":\"lsbtHKzikw\",\"type\":\"paragraph\",\"data\":{\"text\":\"Run this sequence in your terminal to clear out stale CocoaPod builds:\"}},{\"id\":\"IQj91xHFN_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Bash\"}},{\"id\":\"eaG9vVAzx8\",\"type\":\"code\",\"data\":{\"code\":\"cd ios\\nrm -rf Pods Podfile.lock\\npod cache clean --all\\npod install --repo-update\\ncd ..\\n\"}},{\"id\":\"OJIgj8qIdI\",\"type\":\"header\",\"data\":{\"text\":\"3. Production-Ready React Native Code Implementation\",\"level\":2}},{\"id\":\"ZbEopKvwot\",\"type\":\"paragraph\",\"data\":{\"text\":\"Many crashes occur when developers attempt to initialize the payment sheet before validating backend responses. If your API endpoint throws a 500 error and returns <code>undefined<\/code> for <code>paymentIntentClientSecret<\/code>, calling <code>initPaymentSheet<\/code> will cause an uncaught native exception.\"}},{\"id\":\"dtG8botNmd\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is a robust, crash-proof React Native implementation using <code>@stripe\/stripe-react-native<\/code>.\"}},{\"id\":\"5OmfYh19Mp\",\"type\":\"header\",\"data\":{\"text\":\"Step 1: Wrap Your Root Component with <code>&lt;StripeProvider&gt;<\/code>\",\"level\":3}},{\"id\":\"TmQH_lI5EA\",\"type\":\"paragraph\",\"data\":{\"text\":\"In your main <code>App.tsx<\/code> or Root Navigator:\"}},{\"id\":\"3gGapEK_u0\",\"type\":\"paragraph\",\"data\":{\"text\":\"TypeScript\"}},{\"id\":\"IEy9f0gXhz\",\"type\":\"code\",\"data\":{\"code\":\"import React from 'react';\\nimport { StripeProvider } from '@stripe\/stripe-react-native';\\nimport CheckoutScreen from '.\/src\/screens\/CheckoutScreen';\\n\\nconst STRIPE_PUBLISHABLE_KEY = 'pk_test_51Mz...YourKeyHere';\\n\\nexport default function App() {\\n  return (\\n    <StripeProvider\\n      publishableKey={STRIPE_PUBLISHABLE_KEY}\\n      merchantIdentifier=\\\"merchant.com.yourcompany.app\\\" \/\/ Required for Apple Pay\\n    >\\n      <CheckoutScreen \/>\\n    <\/StripeProvider>\\n  );\\n}\\n\"}},{\"id\":\"R1fJbkjP88\",\"type\":\"header\",\"data\":{\"text\":\"Step 2: Safe <code>CheckoutScreen.tsx<\/code> with Full Error Catching\",\"level\":3}},{\"id\":\"VN2kCB4em_\",\"type\":\"paragraph\",\"data\":{\"text\":\"TypeScript\"}},{\"id\":\"BBveQtfUzC\",\"type\":\"code\",\"data\":{\"code\":\"import React, { useState, useEffect } from 'react';\\nimport { View, Text, StyleSheet, TouchableOpacity, ActivityIndicator, Alert } from 'react-native';\\nimport { usePaymentSheet } from '@stripe\/stripe-react-native';\\n\\nexport default function CheckoutScreen() {\\n  const { initPaymentSheet, presentPaymentSheet } = usePaymentSheet();\\n  const [loading, setLoading] = useState(false);\\n\\n  \/\/ Safely fetch payment parameters from your server\\n  const fetchPaymentParams = async () => {\\n    try {\\n      const response = await fetch('https:\/\/your-api-domain.com\/create-payment-intent', {\\n        method: 'POST',\\n        headers: { 'Content-Type': 'application\/json' },\\n        body: JSON.stringify({ amount: 2500, currency: 'usd' }),\\n      });\\n\\n      if (!response.ok) {\\n        throw new Error(`Server Error Code: ${response.status}`);\\n      }\\n\\n      const data = await response.json();\\n\\n      if (!data.paymentIntent) {\\n        throw new Error('Invalid server response: Missing paymentIntent client secret');\\n      }\\n\\n      return {\\n        paymentIntent: data.paymentIntent,\\n        ephemeralKey: data.ephemeralKey,\\n        customer: data.customer,\\n      };\\n    } catch (error: any) {\\n      console.error('[Stripe Fetch Error]:', error);\\n      Alert.alert('Connection Error', error.message || 'Failed to reach payment server.');\\n      return null;\\n    }\\n  };\\n\\n  \/\/ Initialize Payment Sheet with guard checks\\n  const initializePaymentSheet = async () => {\\n    setLoading(true);\\n\\n    const params = await fetchPaymentParams();\\n    if (!params) {\\n      setLoading(false);\\n      return; \/\/ Stop execution safely if server call failed\\n    }\\n\\n    const { error } = await initPaymentSheet({\\n      merchantDisplayName: 'My Mobile Store',\\n      customerId: params.customer,\\n      customerEphemeralKeySecret: params.ephemeralKey,\\n      paymentIntentClientSecret: params.paymentIntent,\\n      allowsDelayedPaymentMethods: false,\\n      defaultBillingDetails: {\\n        name: 'John Doe',\\n      },\\n    });\\n\\n    if (error) {\\n      console.error('[Stripe Init Error]:', error.code, error.message);\\n      Alert.alert('Payment Setup Failed', error.message);\\n    }\\n\\n    setLoading(false);\\n  };\\n\\n  useEffect(() => {\\n    initializePaymentSheet();\\n  }, []);\\n\\n  \/\/ Open the Stripe Payment Sheet\\n  const handlePayPress = async () => {\\n    const { error } = await presentPaymentSheet();\\n\\n    if (error) {\\n      if (error.code === 'Canceled') {\\n        console.log('User closed payment sheet');\\n      } else {\\n        Alert.alert(`Payment Failed (${error.code})`, error.message);\\n      }\\n    } else {\\n      Alert.alert('Success', 'Your payment was confirmed!');\\n    }\\n  };\\n\\n  return (\\n    <View style={styles.container}>\\n      {loading ? (\\n        <ActivityIndicator size=\\\"large\\\" color=\\\"#635BFF\\\" \/>\\n      ) : (\\n        <TouchableOpacity style={styles.payButton} onPress={handlePayPress}>\\n          <Text style={styles.buttonText}>Pay $25.00<\/Text>\\n        <\/TouchableOpacity>\\n      )}\\n    <\/View>\\n  );\\n}\\n\\nconst styles = StyleSheet.create({\\n  container: {\\n    flex: 1,\\n    justifyContent: 'center',\\n    alignItems: 'center',\\n    padding: 20,\\n    backgroundColor: '#F8F9FA',\\n  },\\n  payButton: {\\n    backgroundColor: '#635BFF',\\n    paddingVertical: 14,\\n    paddingHorizontal: 32,\\n    borderRadius: 8,\\n    elevation: 3,\\n    shadowColor: '#000',\\n    shadowOffset: { width: 0, height: 2 },\\n    shadowOpacity: 0.2,\\n    shadowRadius: 3,\\n  },\\n  buttonText: {\\n    color: '#FFFFFF',\\n    fontSize: 16,\\n    fontWeight: '600',\\n  },\\n});\\n\"}},{\"id\":\"jCTuMk9nnl\",\"type\":\"header\",\"data\":{\"text\":\"4. Backend Validation (Node.js Example)\",\"level\":2}},{\"id\":\"gDF_l1iH7N\",\"type\":\"paragraph\",\"data\":{\"text\":\"To prevent sending malformed payloads to React Native, ensure your backend returns properly structured JSON for PaymentIntents:\"}},{\"id\":\"BMmOSuuhTm\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"arytvhLwS0\",\"type\":\"code\",\"data\":{\"code\":\"const express = require('express');\\nconst app = express();\\nconst stripe = require('stripe')('sk_test_YourSecretKeyHere');\\n\\napp.use(express.json());\\n\\napp.post('\/create-payment-intent', async (req, res) => {\\n  try {\\n    const { amount, currency } = req.body;\\n\\n    const customer = await stripe.customers.create();\\n    \\n    const ephemeralKey = await stripe.ephemeralKeys.create(\\n      { customer: customer.id },\\n      { apiVersion: '2023-10-16' }\\n    );\\n\\n    const paymentIntent = await stripe.paymentIntents.create({\\n      amount: amount || 1000,\\n      currency: currency || 'usd',\\n      customer: customer.id,\\n      automatic_payment_methods: { enabled: true },\\n    });\\n\\n    res.status(200).json({\\n      paymentIntent: paymentIntent.client_secret,\\n      ephemeralKey: ephemeralKey.secret,\\n      customer: customer.id,\\n    });\\n  } catch (error) {\\n    console.error('Stripe API Error:', error.message);\\n    res.status(500).json({ error: error.message });\\n  }\\n});\\n\\napp.listen(3000, () => console.log('Payment server running on port 3000'));\\n\"}},{\"id\":\"ELFhQDY6n3\",\"type\":\"header\",\"data\":{\"text\":\"Summary Checklist to Prevent Future React Native Stripe Crashes\",\"level\":2}},{\"id\":\"OEO8EiOCpf\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before publishing your next React Native update to Google Play or the Apple App Store, run through this checklist:\"}},{\"id\":\"Z0ODnjy-TL\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Android Theme Check:<\/b> Ensure <code>android\/app\/src\/main\/res\/values\/styles.xml<\/code> extends <code>Theme.MaterialComponents<\/code>.\",\"<b>iOS Pods Check:<\/b> Ensure <code>IPHONEOS_DEPLOYMENT_TARGET<\/code> in your <code>Podfile<\/code> is set to <code>13.0<\/code> or higher.\",\"<b>Null-Check Client Secrets:<\/b> Never pass <code>undefined<\/code> to <code>initPaymentSheet()<\/code>. Always guard your state variables.\",\"<b>Test on Physical Devices:<\/b> Always test Apple Pay \/ Google Pay flows on physical iOS and Android hardware rather than emulators.\",\"<b>Keep Package Updated:<\/b> Frequently check for updates with <code>npm outline @stripe\/stripe-react-native<\/code> and read official release notes on the <a target=\\\"_blank\\\" href=\\\"https:\/\/github.com\/stripe\/stripe-react-native\\\">Official Stripe React Native Repository<\/a>.\"]}},{\"id\":\"WpkW5NznUq\",\"type\":\"paragraph\",\"data\":{\"text\":\"Relatated Link:\"}},{\"id\":\"Qv52uL-gvk\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/fix-module-not-found-error-react\\\">How to Fix \\\"Module Not Found\\\" Error in React (Complete Guide with Examples)<\/a>\",\"level\":2}},{\"id\":\"b-eeM8kmXT\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/how-to-handle-multiple-input-fields-react-usestate\\\">How to Handle Multiple Input Fields in React with useState (Clean Code Guide)<\/a>\",\"level\":2}},{\"id\":\"RbqBRJZWuh\",\"type\":\"header\",\"data\":{\"text\":\"<a href=\\\"https:\/\/samwithcode.com\/blog\/react-useeffect-not-working\\\">React useEffect Not Working? Complete Guide to Fix Common Issues (2026)<\/a>\",\"level\":2}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/fix-stripe-sdk-crash-react-native-android-ios-1785870856.jfif","status":"published","excerpt":"Learn how to fix app crashes caused by @stripe\/stripe-react-native on Android and iOS. Complete step-by-step practical guide with native fixes, code examples, and theme solutions.","published_at":"2026-08-04T19:14:15.848000Z","tags":"[\"stripe sdk crash react native\",\"stripe\",\"stripe react\",\"react js\",\"react\",\"web development\",\"android\",\"ios\",\"react native\"]","created_at":"2026-08-04T19:14:16.000000Z","updated_at":"2026-11-24T11:38:57.000000Z","views":30,"scheduled_at":null,"seo":{"id":19,"seoable_type":"App\\Models\\Blog","seoable_id":11,"meta_title":"How to Fix Stripe SDK Crashes in React Native (Android & iOS Complete Guide) | SamWithCode","meta_description":"Learn how to fix app crashes caused by @stripe\/stripe-react-native on Android and iOS. Complete step-by-step practical guide with native fixes, code examples, and theme solutions.","meta_keywords":"stripe react native android crash, ios pod stripe react native crash, theme.materialcomponents stripe react native, react native stripe payment sheet error","meta_image":"seo\/fix-stripe-sdk-crash-react-native-android-ios-1785870856.jfif","og_title":"How to Fix Stripe SDK Crashes in React Native (Android & iOS Complete Guide) | SamWithCode","og_description":"Learn how to fix app crashes caused by @stripe\/stripe-react-native on Android and iOS. Complete step-by-step practical guide with native fixes, code examples, and theme solutions.","og_image":"seo\/fix-stripe-sdk-crash-react-native-android-ios-1785870856.jfif","extra":null,"created_at":"2026-08-04T19:14:16.000000Z","updated_at":"2026-08-04T19:14:16.000000Z"},"category":{"id":2,"name":"Web Development","slug":"web-development","created_at":"2026-07-05T12:39:07.000000Z","updated_at":"2026-07-05T12:39:07.000000Z"}},{"id":10,"user_id":1,"category_id":2,"title":"How to Handle Multiple Input Fields in React with useState (Clean Code Guide)","slug":"how-to-handle-multiple-input-fields-react-usestate","content":"{\"time\":1785781621893,\"blocks\":[{\"id\":\"bPqbydo7cH\",\"type\":\"header\",\"data\":{\"text\":\"<b>Mastering Multiple Form Fields in React Using a Single <code>useState<\/code> Hook<\/b>\",\"level\":2}},{\"id\":\"tnMhUDsDf6\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you have ever built a registration page, a checkout wizard, or a settings panel in React, you have definitely faced the form state headache.\"}},{\"id\":\"-vsvvAFwRt\",\"type\":\"paragraph\",\"data\":{\"text\":\"When you first start out, handling user inputs feels innocent enough. You need a field for a first name? You write a <code>useState<\/code>. You need a last name? You write another <code>useState<\/code>. Before you know it, your component file is stuffed with ten different state hooks, ten individual update handlers, and a mountain of repetitive code.\"}},{\"id\":\"MMsi_YfHFJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this deep-dive guide, we are going to look at why writing separate states for every single input kills your code quality, how Senior and Lead developers manage forms cleanly, and how you can use a <b>single <code>useState<\/code> object with computed property names<\/b> to handle infinite form fields like a pro.\"}},{\"id\":\"VViLMz3Ozk\",\"type\":\"header\",\"data\":{\"text\":\"<b>The Real-World Scenario: Why Form Management Gets Messy<\/b>\",\"level\":2}},{\"id\":\"bDXCqfhVBP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Imagine you are building a user onboarding profile page for a SaaS startup. Your product manager walks up to your desk and hands you a list of required fields:\"}},{\"id\":\"OsigruxQZ4\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"First Name &amp; Last Name\",\"Email Address &amp; Phone Number\",\"Age &amp; Occupation\",\"Bio &amp; Company Name\",\"Notification Preferences (Checkbox)\"]}},{\"id\":\"S1znlF9oaL\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you approach this with the traditional beginner mindset\u2014giving every single field its own isolated state\u2014your component quickly starts looking like an unmaintainable maze of boilerplate code.\"}},{\"id\":\"X3cXgO-gcc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let\u2019s inspect what that \\\"naive\\\" approach looks like in practice.\"}},{\"id\":\"BBqTEkI4IL\",\"type\":\"header\",\"data\":{\"text\":\"<b>The Problem: Multiple <code>useState<\/code> Hooks (The Anti-DRY Approach)<\/b>\",\"level\":2}},{\"id\":\"nwaHz0YaVC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is how a standard profile form looks when you isolate every input into its own state variable:\"}},{\"id\":\"tErUDBDG37\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"x1QuDha-Pq\",\"type\":\"code\",\"data\":{\"code\":\"import React, { useState } from \\\"react\\\";\\n\\nexport default function MessyProfileForm() {\\n  const [firstName, setFirstName] = useState(\\\"\\\");\\n  const [lastName, setLastName] = useState(\\\"\\\");\\n  const [email, setEmail] = useState(\\\"\\\");\\n  const [phone, setPhone] = useState(\\\"\\\");\\n  const [occupation, setOccupation] = useState(\\\"\\\");\\n  const [bio, setBio] = useState(\\\"\\\");\\n\\n  const handleSubmit = (e) => {\\n    e.preventDefault();\\n    \/\/ Imagine gathering all 6 variables here...\\n    console.log({ firstName, lastName, email, phone, occupation, bio });\\n  };\\n\\n  return (\\n    <form onSubmit={handleSubmit} className=\\\"form-container\\\">\\n      <h2>User Profile Setup<\/h2>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        placeholder=\\\"First Name\\\"\\n        value={firstName}\\n        onChange={(e) => setFirstName(e.target.value)}\\n      \/>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        placeholder=\\\"Last Name\\\"\\n        value={lastName}\\n        onChange={(e) => setLastName(e.target.value)}\\n      \/>\\n      \\n      <input\\n        type=\\\"email\\\"\\n        placeholder=\\\"Email Address\\\"\\n        value={email}\\n        onChange={(e) => setEmail(e.target.value)}\\n      \/>\\n      \\n      <input\\n        type=\\\"tel\\\"\\n        placeholder=\\\"Phone Number\\\"\\n        value={phone}\\n        onChange={(e) => setPhone(e.target.value)}\\n      \/>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        placeholder=\\\"Occupation\\\"\\n        value={occupation}\\n        onChange={(e) => setOccupation(e.target.value)}\\n      \/>\\n      \\n      <textarea\\n        placeholder=\\\"Short Bio\\\"\\n        value={bio}\\n        onChange={(e) => setBio(e.target.value)}\\n      \/>\\n\\n      <button type=\\\"submit\\\">Save Profile<\/button>\\n    <\/form>\\n  );\\n}\\n\"}},{\"id\":\"w-KaxWl7L4\",\"type\":\"header\",\"data\":{\"text\":\"<b>Why This Approach Fails in Production Apps:<\/b>\",\"level\":3}},{\"id\":\"D5ITbZs52z\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Massive Boilerplate Bloat:<\/b> For every new input field added to your layout, you have to write a brand new <code>useState<\/code> declaration line <i>and<\/i> a custom inline arrow function for the <code>onChange<\/code> event.\",\"<b>Violation of the DRY Principle (Don't Repeat Yourself):<\/b> You are basically rewriting the exact same assignment logic (<code>(e) =&gt; setX(e.target.value)<\/code>) half a dozen times.\",\"<b>Reset and Validation Nightmares:<\/b> If a user clicks a \\\"Reset Form\\\" button, or if you need to validate that none of these fields are empty before submission, writing logic to clear or check six different state variables becomes extremely tedious and error-prone.\"]}},{\"id\":\"byP1IglhtT\",\"type\":\"header\",\"data\":{\"text\":\"<b>The Clean Code Solution: Single <code>useState<\/code> Object<\/b>\",\"level\":2}},{\"id\":\"BhXAik1B6U\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead of scattering our data across independent state variables, what if we treat the entire form as <b>a single centralized data object<\/b>?\"}},{\"id\":\"jsXiwSrQ51\",\"type\":\"paragraph\",\"data\":{\"text\":\"Think of a form object like a database record or a JSON payload that you would eventually send to an API backend. It naturally belongs together:\"}},{\"id\":\"Gz2iG_NnZq\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"_0v777Oyut\",\"type\":\"code\",\"data\":{\"code\":\"{\\n  firstName: \\\"\\\",\\n  lastName: \\\"\\\",\\n  email: \\\"\\\",\\n  phone: \\\"\\\",\\n  occupation: \\\"\\\",\\n  bio: \\\"\\\"\\n}\\n\"}},{\"id\":\"3oKt_GbEDk\",\"type\":\"paragraph\",\"data\":{\"text\":\"To make this work seamlessly in React without writing individual handlers, we leverage two powerful JavaScript concepts:\"}},{\"id\":\"qMWp_XNkpD\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>The HTML <code>name<\/code> attribute:<\/b> Every input field is given a unique identifier name that matches the exact key inside our state object.\",\"<b>Computed Property Names (<code>[e.target.name]<\/code>):<\/b> JavaScript allows object keys to be evaluated dynamically using square bracket syntax.\"]}},{\"id\":\"9BNkcqzq3G\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let\u2019s refactor our messy profile form into a clean, scalable component:\"}},{\"id\":\"ZQjmm035g6\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"cXAbVKw4An\",\"type\":\"code\",\"data\":{\"code\":\"import React, { useState } from \\\"react\\\";\\n\\nexport default function OptimizedProfileForm() {\\n  \/\/ 1. Initialize state as a single structured object\\n  const [formData, setFormData] = useState({\\n    firstName: \\\"\\\",\\n    lastName: \\\"\\\",\\n    email: \\\"\\\",\\n    phone: \\\"\\\",\\n    occupation: \\\"\\\",\\n    bio: \\\"\\\",\\n  });\\n\\n  \/\/ 2. A single universal event handler for all text\/textarea inputs\\n  const handleChange = (e) => {\\n    const { name, value } = e.target;\\n\\n    setFormData((prevData) => ({\\n      ...prevData,      \/\/ Preserve all other unmodified fields\\n      [name]: value,    \/\/ Dynamically target and update the active field\\n    }));\\n  };\\n\\n  const handleSubmit = (e) => {\\n    e.preventDefault();\\n    console.log(\\\"Ready for API Submission:\\\", formData);\\n    \/\/ You can directly pass `formData` to your backend fetch request!\\n  };\\n\\n  return (\\n    <form onSubmit={handleSubmit} className=\\\"form-container\\\">\\n      <h2>User Profile Setup<\/h2>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        name=\\\"firstName\\\"\\n        placeholder=\\\"First Name\\\"\\n        value={formData.firstName}\\n        onChange={handleChange}\\n      \/>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        name=\\\"lastName\\\"\\n        placeholder=\\\"Last Name\\\"\\n        value={formData.lastName}\\n        onChange={handleChange}\\n      \/>\\n      \\n      <input\\n        type=\\\"email\\\"\\n        name=\\\"email\\\"\\n        placeholder=\\\"Email Address\\\"\\n        value={formData.email}\\n        onChange={handleChange}\\n      \/>\\n      \\n      <input\\n        type=\\\"tel\\\"\\n        name=\\\"phone\\\"\\n        placeholder=\\\"Phone Number\\\"\\n        value={formData.phone}\\n        onChange={handleChange}\\n      \/>\\n      \\n      <input\\n        type=\\\"text\\\"\\n        name=\\\"occupation\\\"\\n        placeholder=\\\"Occupation\\\"\\n        value={formData.occupation}\\n        onChange={handleChange}\\n      \/>\\n      \\n      <textarea\\n        name=\\\"bio\\\"\\n        placeholder=\\\"Short Bio\\\"\\n        value={formData.bio}\\n        onChange={handleChange}\\n      \/>\\n\\n      <button type=\\\"submit\\\">Save Profile<\/button>\\n    <\/form>\\n  );\\n}\\n\"}},{\"id\":\"9AT_Fsajha\",\"type\":\"header\",\"data\":{\"text\":\"<b>Deep Dive: Under the Hood of the Optimized Handler<\/b>\",\"level\":2}},{\"id\":\"eVwup81GcS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's break down line-by-line why this clean approach works so efficiently:\"}},{\"id\":\"r_EF24V3Ib\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"lu7niidv-n\",\"type\":\"code\",\"data\":{\"code\":\"const handleChange = (e) => {\\n  const { name, value } = e.target;\\n  \\n  setFormData((prevData) => ({\\n    ...prevData,\\n    [name]: value,\\n  }));\\n};\\n\"}},{\"id\":\"VXB4-NQDz7\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Destructuring <code>name<\/code> and <code>value<\/code>:<\/b> When a user types inside the email input field, <code>e.target.name<\/code> evaluates to <code>\\\"email\\\"<\/code>, and <code>e.target.value<\/code> evaluates to whatever string they just typed (e.g., <code>\\\"alex@gmail.com\\\"<\/code>).\",\"<b>The Spread Operator (<code>...prevData<\/code>):<\/b> In React, state updates <i>replace<\/i> data rather than automatically merging it like class-based <code>this.setState<\/code> used to. If we omitted the spread operator, typing in the email field would completely wipe out <code>firstName<\/code>, <code>lastName<\/code>, and all other fields from our state object. The spread operator copies over everything currently inside the state.\",\"<b>Computed Property Brackets (<code>[name]: value<\/code>):<\/b> If you wrote <code>{ name: value }<\/code>, JavaScript would literally create a property named literally <code>\\\"name\\\"<\/code>. By wrapping it in square brackets <code>[name]<\/code>, JavaScript reads the <i>value<\/i> stored inside the <code>name<\/code> constant (which is <code>\\\"email\\\"<\/code>), successfully resulting in <code>{ email: \\\"alex@gmail.com\\\" }<\/code>.\"]}},{\"id\":\"Z5bqpQRJ2Q\",\"type\":\"header\",\"data\":{\"text\":\"<b>Real-World Advanced Example: Handling Checkboxes, Selects, and Radio Buttons<\/b>\",\"level\":2}},{\"id\":\"D8SVkRpmSe\",\"type\":\"paragraph\",\"data\":{\"text\":\"Production-grade forms never consist solely of standard text inputs. You will always need to process special input types\u2014such as terms-and-conditions checkboxes, toggle switches, or dropdown select boxes.\"}},{\"id\":\"Z9Y3jkbaf3\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because checkboxes use <code>e.target.checked<\/code> (a boolean) instead of <code>e.target.value<\/code> (a string), our single handler needs a tiny adjustment to check the input type.\"}},{\"id\":\"P-7wZddGB6\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let\u2019s look at a complete real-world registration form featuring a dropdown select and a terms-and-conditions checkbox:\"}},{\"id\":\"n5jAblLY6B\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"kv0mah930s\",\"type\":\"code\",\"data\":{\"code\":\"import React, { useState } from \\\"react\\\";\\n\\nexport default function AdvancedRegistrationForm() {\\n  const [formData, setFormData] = useState({\\n    username: \\\"\\\",\\n    experienceLevel: \\\"Junior\\\", \/\/ default dropdown selection\\n    subscribeNewsletter: false, \/\/ boolean state for checkbox\\n  });\\n\\n  const handleUniversalChange = (e) => {\\n    const { name, value, type, checked } = e.target;\\n\\n    setFormData((prevData) => ({\\n      ...prevData,\\n      \/\/ Ternary condition: if it's a checkbox, use 'checked', else use 'value'\\n      [name]: type === \\\"checkbox\\\" ? checked : value,\\n    }));\\n  };\\n\\n  const handleSubmit = (e) => {\\n    e.preventDefault();\\n    console.log(\\\"Final Submitted Form Payload:\\\", formData);\\n  };\\n\\n  return (\\n    <form onSubmit={handleSubmit} className=\\\"advanced-form\\\">\\n      <h2>Create Developer Account<\/h2>\\n\\n      {\/* Standard Text Input *\/}\\n      <div className=\\\"field-group\\\">\\n        <label>Username<\/label>\\n        <input\\n          type=\\\"text\\\"\\n          name=\\\"username\\\"\\n          value={formData.username}\\n          onChange={handleUniversalChange}\\n          placeholder=\\\"Enter username\\\"\\n        \/>\\n      <\/div>\\n\\n      {\/* Select Dropdown *\/}\\n      <div className=\\\"field-group\\\">\\n        <label>Experience Level<\/label>\\n        <select\\n          name=\\\"experienceLevel\\\"\\n          value={formData.experienceLevel}\\n          onChange={handleUniversalChange}\\n        >\\n          <option value=\\\"Junior\\\">Junior Developer<\/option>\\n          <option value=\\\"Mid-Level\\\">Mid-Level Developer<\/option>\\n          <option value=\\\"Senior\\\">Senior Developer<\/option>\\n        <\/select>\\n      <\/div>\\n\\n      {\/* Checkbox Input *\/}\\n      <div className=\\\"field-group checkbox-wrapper\\\">\\n        <label>\\n          <input\\n            type=\\\"checkbox\\\"\\n            name=\\\"subscribeNewsletter\\\"\\n            checked={formData.subscribeNewsletter}\\n            onChange={handleUniversalChange}\\n          \/>\\n          Subscribe to weekly coding newsletters\\n        <\/label>\\n      <\/div>\\n\\n      <button type=\\\"submit\\\" className=\\\"submit-btn\\\">Register Now<\/button>\\n    <\/form>\\n  );\\n}\\n\"}},{\"id\":\"-LVBNffBvb\",\"type\":\"header\",\"data\":{\"text\":\"<b>Conclusion<\/b>\",\"level\":2}},{\"id\":\"c1CdXq4RHZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Moving away from dozens of fragmented <code>useState<\/code> hooks and adopting a single object-based state structure completely transforms how clean and maintainable your React components feel.\"}},{\"id\":\"WJKwJ0-crK\",\"type\":\"paragraph\",\"data\":{\"text\":\"By leveraging the power of input <code>name<\/code> attributes, the object spread operator (<code>...<\/code>), and computed property syntax (<code>[name]<\/code>), you can scale a form from 3 fields to 30 fields while keeping your change-handling logic confined to just 5 lines of code.\"}},{\"id\":\"8OpGlJa_Xr\",\"type\":\"header\",\"data\":{\"text\":\"<b>Recommended YouTube Tutorial Reference<\/b>\",\"level\":3}},{\"id\":\"dfmhWEnYFY\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you prefer watching a complete visual walkthrough with live coding and architectural explanations, check out the companion video tutorial on our channel:\"}},{\"id\":\"0ygWOY9oYy\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>YouTube Video Title:<\/b> <i>Mastering Multiple Form Fields in React Using a Single useState Hook (Clean Code Guide)<\/i>\",\"<b>Topics Covered Visually:<\/b> Refactoring anti-DRY code, setting up dynamic object state, handling checkboxes, and preparing payloads for REST APIs.\"]}},{\"id\":\"atwji-lA-3\",\"type\":\"embed\",\"data\":{\"service\":\"youtube\",\"source\":\"https:\/\/youtu.be\/9DOuSDMpuPg?si=ZvaeFq9TbQt7OD72\",\"embed\":\"https:\/\/www.youtube.com\/embed\/9DOuSDMpuPg?\",\"width\":580,\"height\":320,\"caption\":\"\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/how-to-handle-multiple-input-fields-react-usestate-1785781663.png","status":"published","excerpt":"Learn how to efficiently manage multiple form input fields in React using a single useState hook. Stop writing repetitive code and master dynamic state management with code examples.","published_at":"2026-08-03T18:27:01.894000Z","tags":"[\"web development\",\"React\",\"JavaScript\",\"Frontend\",\"html\",\"React Js\",\"javascript\",\"react\",\"react js\"]","created_at":"2026-08-03T18:27:43.000000Z","updated_at":"2026-11-08T20:06:46.000000Z","views":37,"scheduled_at":null,"seo":{"id":18,"seoable_type":"App\\Models\\Blog","seoable_id":10,"meta_title":"How to Handle Multiple Input Fields in React with useState (Clean Code Guide) | SamWithCode","meta_description":"Learn how to efficiently manage multiple form input fields in React using a single useState hook. Stop writing repetitive code and master dynamic state management with code examples.","meta_keywords":"React multiple inputs useState, handle multiple form fields React, React form state management, React onChange multiple inputs.","meta_image":"seo\/how-to-handle-multiple-input-fields-react-usestate-1785781663.png","og_title":"How to Handle Multiple Input Fields in React with useState (Clean Code Guide) | SamWithCode","og_description":"Learn how to efficiently manage multiple form input fields in React using a single useState hook. Stop writing repetitive code and master dynamic state management with code examples.","og_image":"seo\/how-to-handle-multiple-input-fields-react-usestate-1785781663.png","extra":null,"created_at":"2026-08-03T18:27:43.000000Z","updated_at":"2026-08-03T18:27:43.000000Z"},"category":{"id":2,"name":"Web Development","slug":"web-development","created_at":"2026-07-05T12:39:07.000000Z","updated_at":"2026-07-05T12:39:07.000000Z"}},{"id":9,"user_id":1,"category_id":2,"title":"How to Build a Google Keep Clone with React.js (Class Components)","slug":"build-google-keep-clone-react-class-components","content":"{\"time\":1785653523307,\"blocks\":[{\"id\":\"jvYUZijTac\",\"type\":\"paragraph\",\"data\":{\"text\":\"Every developer\u2019s journey has a few rite-of-passage projects. Building a Todo list is usually the first. But if you really want to level up your frontend skills and understand how data flows through an application, building a <b>Google Keep Clone<\/b> is the ultimate next step.\"}},{\"id\":\"cjTWM5Yzsj\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this comprehensive, step-by-step guide, we are going to build a fully functional Google Keep clone from scratch using <b>React.js<\/b>.\"}},{\"id\":\"uRDLjmnlpp\",\"type\":\"paragraph\",\"data\":{\"text\":\"While modern React heavily features Functional Components and Hooks, master modern web development requires a rock-solid understanding of <b>Class-Based Components<\/b> and <b>React Lifecycle Methods<\/b>. Many massive enterprise codebases still rely on class components, and knowing how they work under the hood makes you a far more versatile developer.\"}},{\"id\":\"o8mtwcuXY5\",\"type\":\"paragraph\",\"data\":{\"text\":\"By the end of this tutorial, you will have a sleek, responsive note-taking application complete with persistent data storage using the browser\u2019s <code>localStorage<\/code>.\"}},{\"id\":\"POjGq-PXhQ\",\"type\":\"header\",\"data\":{\"text\":\"What We Will Build: Core Features\",\"level\":2}},{\"id\":\"gk9awADvXI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before we dive into the code, let\u2019s look at the core functionalities our Google Keep clone will feature:\"}},{\"id\":\"MH1t6vhlpS\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>Dynamic UI Layout:<\/b> A clean, responsive interface powered by Bootstrap, featuring an intuitive input form and neat note cards.\",\"<b>State Management in Class Components:<\/b> Utilizing constructors, initializing state, and correctly binding the <code>this<\/code> keyword.\",\"<b>React Lifecycle Methods:<\/b> Mastering <code>componentDidMount<\/code> and <code>componentDidUpdate<\/code> to handle real-time data persistence.\",\"<b>Full CRUD Functionality:<\/b> Adding new notes, dynamically rendering them using JavaScript array methods, and deleting them seamlessly.\",\"<b>Persistent Storage:<\/b> Syncing our React state with the browser's <code>localStorage<\/code> so users never lose their notes on a page refresh.\"]}},{\"id\":\"SHSZ5KF4XL\",\"type\":\"header\",\"data\":{\"text\":\"Step 1: Project Setup and UI Architecture\",\"level\":2}},{\"id\":\"4XJh0WMmCy\",\"type\":\"paragraph\",\"data\":{\"text\":\"First things first: let's get our environment ready. We will start by creating a fresh React application and integrating Bootstrap to keep our styling quick and highly responsive.\"}},{\"id\":\"uPH69yqrRB\",\"type\":\"header\",\"data\":{\"text\":\"Initializing the Project\",\"level\":3}},{\"id\":\"faGu54Yg3E\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open your terminal, navigate to your development directory, and run the following commands:\"}},{\"id\":\"rp50eyxDld\",\"type\":\"paragraph\",\"data\":{\"text\":\"Bash\"}},{\"id\":\"59bL-l-mq6\",\"type\":\"code\",\"data\":{\"code\":\"npx create-react-app google-keep-clone\\ncd google-keep-clone\\nnpm install bootstrap\\n\"}},{\"id\":\"BJyLYYlIpt\",\"type\":\"header\",\"data\":{\"text\":\"Structuring Our Components\",\"level\":3}},{\"id\":\"8-h111C84g\",\"type\":\"paragraph\",\"data\":{\"text\":\"A clean project layout makes debugging a breeze. Inside your <code>src<\/code> directory, create a folder named <code>components<\/code>. We will break our application down into three primary components:\"}},{\"id\":\"Ktr1IncX2X\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Header:<\/b> A simple, elegant top navigation bar.\",\"<b>CreateNote:<\/b> The input area where users type their titles and descriptions.\",\"<b>Note:<\/b> The individual card component that displays the saved note.\"]}},{\"id\":\"uNq9IjGIK9\",\"type\":\"paragraph\",\"data\":{\"text\":\"To include Bootstrap's styling across the entire project, open your <code>src\/index.js<\/code> file and add this import statement at the top:\"}},{\"id\":\"SlBuodmjAg\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"gbGHfIc1_e\",\"type\":\"code\",\"data\":{\"code\":\"import 'bootstrap\/dist\/css\/bootstrap.min.css';\\n\"}},{\"id\":\"D9f7s2KHBj\",\"type\":\"header\",\"data\":{\"text\":\"Step 2: Deep Dive into Class-Based Components\",\"level\":2}},{\"id\":\"RMNFrFIx8N\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now that our boilerplate is set up, let's look at the backbone of this project: <b>React Class Components<\/b>.\"}},{\"id\":\"CxVUy_LIRD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unlike functional components that use the <code>useState<\/code> hook, class components use a JavaScript class that extends <code>React.Component<\/code>. They rely on a <code>constructor<\/code> to initialize state and require explicit binding of methods so that the <code>this<\/code> keyword refers to the component instance.\"}},{\"id\":\"fQQqIB3EHg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is how we initialize our main <code>App.js<\/code> component:\"}},{\"id\":\"ohwXBR7IqB\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"GV9lrl2sje\",\"type\":\"code\",\"data\":{\"code\":\"import React, { Component } from 'react';\\nimport Header from '.\/components\/Header';\\nimport CreateNote from '.\/components\/CreateNote';\\nimport Note from '.\/components\/Note';\\n\\nclass App extends Component {\\n  constructor(props) {\\n    super(props);\\n    \\n    \/\/ Initializing the state\\n    this.state = {\\n      notes: []\\n    };\\n\\n    \/\/ Binding methods to ensure 'this' context is preserved\\n    this.addNote = this.addNote.bind(this);\\n    this.deleteNote = this.deleteNote.bind(this);\\n  }\\n\\n  render() {\\n    return (\\n      <div className=\\\"app-container\\\">\\n        <Header \/>\\n        <div className=\\\"container my-5\\\">\\n          <CreateNote onAdd={this.addNote} \/>\\n          {\/* Notes will be rendered here *\/}\\n        <\/div>\\n      <\/div>\\n    );\\n  }\\n}\\n\\nexport default App;\\n\"}},{\"id\":\"ar_XHLHLBf\",\"type\":\"header\",\"data\":{\"text\":\"Pro-Tip: Demystifying <code>this<\/code>\",\"level\":3}},{\"id\":\"7II7V9CQ2j\",\"type\":\"paragraph\",\"data\":{\"text\":\"In JavaScript, the value of <code>this<\/code> is determined by how a function is called. In React class components, if you pass a method down to a child component (like passing <code>this.addNote<\/code> to <code>CreateNote<\/code>) without binding it in the constructor, <code>this<\/code> will return <code>undefined<\/code> when the function executes. Always remember to bind your custom methods!\"}},{\"id\":\"wo1eTM_dga\",\"type\":\"header\",\"data\":{\"text\":\"Step 3: Mastering React Lifecycle Methods\",\"level\":2}},{\"id\":\"BXdWyfhhDT\",\"type\":\"paragraph\",\"data\":{\"text\":\"One of the most crucial concepts in class-based React development is the component lifecycle. Every component goes through a cycle of creation (mounting), growth (updating), and death (unmounting).\"}},{\"id\":\"IVjlqlUA_n\",\"type\":\"paragraph\",\"data\":{\"text\":\"To make our application functional even after a user closes their browser tab, we will leverage two essential lifecycle methods: <code>componentDidMount<\/code> and <code>componentDidUpdate<\/code>.\"}},{\"id\":\"dqxBAZtbLZ\",\"type\":\"header\",\"data\":{\"text\":\"1. Fetching Data with <code>componentDidMount<\/code>\",\"level\":3}},{\"id\":\"6Gb9pMQ4xT\",\"type\":\"paragraph\",\"data\":{\"text\":\"This method runs <b>exactly once<\/b> immediately after the component is rendered into the DOM. It is the perfect place to fetch external data or pull existing items out of <code>localStorage<\/code>.\"}},{\"id\":\"dVtLa27Jc7\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"i6Eof7_jcE\",\"type\":\"code\",\"data\":{\"code\":\"componentDidMount() {\\n  try {\\n    const savedNotes = localStorage.getItem('keep_notes');\\n    if (savedNotes) {\\n      this.setState({ notes: JSON.parse(savedNotes) });\\n    }\\n  } catch (error) {\\n    console.error(\\\"Error loading notes from localStorage:\\\", error);\\n  }\\n}\\n\"}},{\"id\":\"qVF5rkteE6\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Why use <code>JSON.parse<\/code>?<\/b> <code>localStorage<\/code> can only store data as raw strings. When we pull our data out, we must convert that string back into a readable JavaScript array using <code>JSON.parse()<\/code>.\"}},{\"id\":\"mOQELLmCt4\",\"type\":\"header\",\"data\":{\"text\":\"2. Synchronizing Data with <code>componentDidUpdate<\/code>\",\"level\":3}},{\"id\":\"-wHgN9ovnR\",\"type\":\"paragraph\",\"data\":{\"text\":\"This method fires automatically whenever a component's state or props change. We can use it to listen for changes in our <code>notes<\/code> array. Whenever a note is added or removed, we instantly update <code>localStorage<\/code>.\"}},{\"id\":\"Z_tBMGK1wa\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"56oB9Se13Q\",\"type\":\"code\",\"data\":{\"code\":\"componentDidUpdate(prevProps, prevState) {\\n  \/\/ Always compare the current state to the previous state to avoid infinite loops!\\n  if (prevState.notes !== this.state.notes) {\\n    localStorage.setItem('keep_notes', JSON.stringify(this.state.notes));\\n  }\\n}\\n\"}},{\"id\":\"ckndFoA5p0\",\"type\":\"header\",\"data\":{\"text\":\"Step 4: Implementing CRUD Operations\",\"level\":2}},{\"id\":\"wFe4hx_LZ0\",\"type\":\"paragraph\",\"data\":{\"text\":\"With our architecture and state management firmly established, it is time to build the actual note-taking mechanics.\"}},{\"id\":\"l2iA3FhJPM\",\"type\":\"header\",\"data\":{\"text\":\"1. Creating New Notes (<code>CreateNote.js<\/code>)\",\"level\":3}},{\"id\":\"8dWAiVFLR_\",\"type\":\"paragraph\",\"data\":{\"text\":\"The <code>CreateNote<\/code> component needs to capture user input for both the title and the note content, hold that temporary data in its local state, and then pass it back up to <code>App.js<\/code> when the user clicks submit.\"}},{\"id\":\"mHVuujSSdt\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is the implementation of the form handling:\"}},{\"id\":\"yUvdJBiRjH\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"Wh8F3KD1Kb\",\"type\":\"code\",\"data\":{\"code\":\"import React, { Component } from 'react';\\n\\nclass CreateNote extends Component {\\n  constructor(props) {\\n    super(props);\\n    this.state = {\\n      title: \\\"\\\",\\n      content: \\\"\\\"\\n    };\\n    this.handleChange = this.handleChange.bind(this);\\n    this.submitNote = this.submitNote.bind(this);\\n  }\\n\\n  handleChange(event) {\\n    const { name, value } = event.target;\\n    this.setState({ [name]: value });\\n  }\\n\\n  submitNote(event) {\\n    event.preventDefault();\\n    if (!this.state.title && !this.state.content) return; \/\/ Prevent empty notes\\n    \\n    this.props.onAdd(this.state);\\n    this.setState({ title: \\\"\\\", content: \\\"\\\" }); \/\/ Reset input fields\\n  }\\n\\n  render() {\\n    return (\\n      <div className=\\\"card p-3 shadow-sm mx-auto my-4\\\" style={{ maxWidth: \\\"500px\\\" }}>\\n        <form onSubmit={this.submitNote}>\\n          <input\\n            type=\\\"text\\\"\\n            name=\\\"title\\\"\\n            placeholder=\\\"Title\\\"\\n            className=\\\"form-control mb-2 border-0 fw-bold shadow-none\\\"\\n            value={this.state.title}\\n            onChange={this.handleChange}\\n          \/>\\n          <textarea\\n            name=\\\"content\\\"\\n            placeholder=\\\"Take a note...\\\"\\n            rows=\\\"3\\\"\\n            className=\\\"form-control border-0 shadow-none\\\"\\n            value={this.state.content}\\n            onChange={this.handleChange}\\n          \/>\\n          <button type=\\\"submit\\\" className=\\\"btn btn-warning float-end rounded-circle mt-2 shadow-sm\\\">\\n            +\\n          <\/button>\\n        <\/form>\\n      <\/div>\\n    );\\n  }\\n}\\n\\nexport default CreateNote;\\n\"}},{\"id\":\"SruQZy9_q-\",\"type\":\"paragraph\",\"data\":{\"text\":\"Back in <code>App.js<\/code>, we handle the incoming new note object and append it to our state array securely without modifying the original state directly:\"}},{\"id\":\"tbYujr2mqj\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"q9MVoWanUd\",\"type\":\"code\",\"data\":{\"code\":\"addNote(newNote) {\\n  this.setState(prevState => {\\n    return { notes: [...prevState.notes, newNote] };\\n  });\\n}\\n\"}},{\"id\":\"w33I9ckGgP\",\"type\":\"header\",\"data\":{\"text\":\"2. Dynamically Rendering the Notes\",\"level\":3}},{\"id\":\"YQ5gPxSGLB\",\"type\":\"paragraph\",\"data\":{\"text\":\"To show our list of notes on screen, we use the JavaScript <code>.map()<\/code> function. This maps over our <code>notes<\/code> state array and converts each raw object into a visual <code>&lt;Note\/&gt;<\/code> card component.\"}},{\"id\":\"3YJI0f1lXD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Inside the <code>render()<\/code> method of <code>App.js<\/code>:\"}},{\"id\":\"HtaaFdUnOJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"wOZ7DKIdDa\",\"type\":\"code\",\"data\":{\"code\":\"<div className=\\\"row\\\">\\n  {this.state.notes.map((noteItem, index) => {\\n    return (\\n      <div className=\\\"col-md-4 my-3\\\" key={index}>\\n        <Note\\n          id={index}\\n          title={noteItem.title}\\n          content={noteItem.content}\\n          onDelete={this.deleteNote}\\n        \/>\\n      <\/div>\\n    );\\n  })}\\n<\/div>\\n\"}},{\"id\":\"qQJCtswr0f\",\"type\":\"header\",\"data\":{\"text\":\"3. Deleting Notes by Index\",\"level\":3}},{\"id\":\"iKMoKbOCX3\",\"type\":\"paragraph\",\"data\":{\"text\":\"To delete a note, we pass its <code>index<\/code> back to the parent component. We then use the <code>.filter()<\/code> method to create a brand new array that excludes the note matching that specific index.\"}},{\"id\":\"_cRfwUgsd7\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"jt1PvKA7eD\",\"type\":\"code\",\"data\":{\"code\":\"deleteNote(id) {\\n  this.setState(prevState => {\\n    return {\\n      notes: prevState.notes.filter((noteItem, index) => {\\n        return index !== id;\\n      })\\n    };\\n  });\\n}\\n\"}},{\"id\":\"o3KtpC0zBP\",\"type\":\"paragraph\",\"data\":{\"text\":\"And here is our lightweight, clean <code>Note.js<\/code> component:\"}},{\"id\":\"btBlpy7Xsq\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"72GqmhW4eq\",\"type\":\"code\",\"data\":{\"code\":\"import React, { Component } from 'react';\\n\\nclass Note extends Component {\\n  render() {\\n    return (\\n      <div className=\\\"card h-100 shadow-sm\\\">\\n        <div className=\\\"card-body d-flex flex-column justify-content-between\\\">\\n          <div>\\n            <h5 className=\\\"card-title fw-bold\\\">{this.props.title}<\/h5>\\n            <p className=\\\"card-text text-secondary\\\" style={{ whiteSpace: \\\"pre-wrap\\\" }}>\\n              {this.props.content}\\n            <\/p>\\n          <\/div>\\n          <button\\n            className=\\\"btn btn-outline-danger btn-sm align-self-end mt-3 border-0\\\"\\n            onClick={() => this.props.onDelete(this.props.id)}\\n          >\\n            Delete\\n          <\/button>\\n        <\/div>\\n      <\/div>\\n    );\\n  }\\n}\\n\\nexport default Note;\\n\"}},{\"id\":\"2OJXzOGoWl\",\"type\":\"header\",\"data\":{\"text\":\"Step 5: Common Pitfalls and Troubleshooting\",\"level\":2}},{\"id\":\"oTfGlxXdx9\",\"type\":\"paragraph\",\"data\":{\"text\":\"When building class-based applications, even seasoned developers run into standard architectural hiccups. Keep an eye out for these errors:\"}},{\"id\":\"oiS3Fxtkb6\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>State Mutation Bugs:<\/b> Never write <code>this.state.notes.push(newNote)<\/code>. React cannot track direct mutations, meaning your UI will not re-render. Always use <code>this.setState()<\/code>.\",\"<b>Infinite Component Updates:<\/b> If you run <code>this.setState()<\/code> inside <code>componentDidUpdate<\/code> without wrapping it in a conditional check (comparing <code>prevState<\/code> to <code>this.state<\/code>), your application will get stuck in an infinite rendering loop and crash.\",\"<b>Stringification Errors:<\/b> Trying to save raw arrays directly to <code>localStorage<\/code> will result in the string <code>\\\"[object Object]\\\"<\/code>. Always run data through <code>JSON.stringify()<\/code> before saving.\"]}},{\"id\":\"vWYA_Lbs7w\",\"type\":\"header\",\"data\":{\"text\":\"Conclusion: Expanding the Project\",\"level\":2}},{\"id\":\"unMqHiB9fm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Congratulations! You have successfully built a fully operational Google Keep Clone using React class components and persistent browser storage.\"}},{\"id\":\"fMdm1kiYdG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Through this project, you have mastered:\"}},{\"id\":\"5MMCZ6msgk\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Setting up modular React component systems.\",\"Handling forms, state mutations, and scope binding in class structures.\",\"Leveraging component lifecycles to sync runtime application memory with <code>localStorage<\/code>.\"]}},{\"id\":\"F4DIAa90rk\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Where should you go from here?<\/b> If you want to push this project further, try adding these features:\"}},{\"id\":\"ZnjEACKX-Y\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b>Search Functionality:<\/b> Add an input bar in the header to filter notes by title keywords.\",\"<b>Color Themes:<\/b> Allow users to change the background color of individual notes just like in the real Google Keep app.\",\"<b>Edit Functionality:<\/b> Allow users to double-click a note card to update its content directly.\"]}},{\"id\":\"cctSHSe3sl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Happy coding, and see you in the next tutorial!\"}},{\"id\":\"SwV1veg5HZ\",\"type\":\"embed\",\"data\":{\"service\":\"youtube\",\"source\":\"https:\/\/youtu.be\/xcoWTsttOJ0?si=J18jNIgqb28Tnmeu\",\"embed\":\"https:\/\/www.youtube.com\/embed\/xcoWTsttOJ0?\",\"width\":580,\"height\":320,\"caption\":\"\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/build-google-keep-clone-react-class-components-1785653536.png","status":"published","excerpt":"Learn how to build a fully functional Google Keep Clone using React.js class-based components. Master state management, component lifecycles, and localStorage data persistence in this ultimate beginner-friendly guide.","published_at":"2026-08-02T06:52:03.315000Z","tags":"[\"web development\",\"react js\",\"react\",\"google\",\"google project\",\"Class Components\",\"LocalStorage\",\"JavaScript\",\"Frontend\",\"Frontend Development\",\"Google Keep Clone\",\"Web Development Tutorial\"]","created_at":"2026-08-02T06:52:16.000000Z","updated_at":"2026-11-25T05:50:43.000000Z","views":22,"scheduled_at":null,"seo":{"id":17,"seoable_type":"App\\Models\\Blog","seoable_id":9,"meta_title":"How to Build a Google Keep Clone with React.js (Class Components & LocalStorage) | SamWithCode","meta_description":"Learn how to build a fully functional Google Keep Clone using React.js class-based components. Master state management, component lifecycles, and localStorage data persistence in this ultimate beginner-friendly guide.","meta_keywords":"React.js, Class Components, LocalStorage, JavaScript, Frontend Development, Google Keep Clone, Web Development Tutorial","meta_image":"seo\/build-google-keep-clone-react-class-components-1785653536.png","og_title":"How to Build a Google Keep Clone with React.js (Class Components & LocalStorage) | SamWithCode","og_description":"Learn how to build a fully functional Google Keep Clone using React.js class-based components. Master state management, component lifecycles, and localStorage data persistence in this ultimate beginner-friendly guide.","og_image":"seo\/build-google-keep-clone-react-class-components-1785653536.png","extra":null,"created_at":"2026-08-02T06:52:16.000000Z","updated_at":"2026-08-02T06:52:16.000000Z"},"category":{"id":2,"name":"Web Development","slug":"web-development","created_at":"2026-07-05T12:39:07.000000Z","updated_at":"2026-07-05T12:39:07.000000Z"}}],"first_page_url":"https:\/\/www.samwithcode.com\/blogs?page=1","from":1,"last_page":3,"last_page_url":"https:\/\/www.samwithcode.com\/blogs?page=3","links":[{"url":null,"label":"&laquo; Previous","active":false},{"url":"https:\/\/www.samwithcode.com\/blogs?page=1","label":"1","active":true},{"url":"https:\/\/www.samwithcode.com\/blogs?page=2","label":"2","active":false},{"url":"https:\/\/www.samwithcode.com\/blogs?page=3","label":"3","active":false},{"url":"https:\/\/www.samwithcode.com\/blogs?page=2","label":"Next &raquo;","active":false}],"next_page_url":"https:\/\/www.samwithcode.com\/blogs?page=2","path":"https:\/\/www.samwithcode.com\/blogs","per_page":4,"prev_page_url":null,"to":4,"total":9},"trending":[{"id":16,"user_id":1,"category_id":2,"title":"JavaScript E-commerce Project \u2013 Search, Filter & Add to Cart","slug":"javascript-e-commerce-product-page-project-search-filter-sort-add-to-cart-using-localstorage","content":"{\"time\":1795239794726,\"blocks\":[{\"id\":\"f_juwDyusT\",\"type\":\"header\",\"data\":{\"text\":\"JavaScript E-commerce Product Page Project \u2013 Search, Filter, Sort &amp; Add to Cart Using LocalStorage\",\"level\":2}},{\"id\":\"mAwYbxQKtB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Learn how to build a complete e-commerce product listing page using HTML, CSS, and Vanilla JavaScript. In this beginner-friendly project, you will create product cards, search products, filter by category and price, sort products, manage a shopping cart, update quantities, calculate totals, and save cart data using LocalStorage.\"}},{\"id\":\"18C0jlSYGf\",\"type\":\"header\",\"data\":{\"text\":\"What Are We Going to Learn in This Project?\",\"level\":2}},{\"id\":\"kbqjfap6SF\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this project, we will build a product page similar to the product listing pages you see on online shopping websites.\"}},{\"id\":\"Sed8SE07ts\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead of learning JavaScript concepts only through small examples, we will use them to build a practical project.\"}},{\"id\":\"Hc9GvZGm1t\",\"type\":\"paragraph\",\"data\":{\"text\":\"By completing this project, you will understand how JavaScript handles products, filters, user interactions, cart operations, and browser storage.\"}},{\"id\":\"R9rvo9awcv\",\"type\":\"header\",\"data\":{\"text\":\"JavaScript Concepts We Will Learn\",\"level\":3}},{\"id\":\"QduFf0mdUb\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"JavaScript Arrays: Store multiple product objects in an array.\",\"JavaScript Objects: Store product information such as name, price, category, rating, and stock status.\",\"DOM Manipulation: Display products dynamically on the webpage.\",\"Array <code>map()<\/code>: Understand how to transform array data.\",\"Array <code>filter()<\/code>: Filter products according to user selections.\",\"Array <code>sort()<\/code>: Sort products by price and rating.\",\"Array <code>find()<\/code>: Find a particular product using its ID.\",\"Array <code>reduce()<\/code>: Calculate the total cart price.\",\"Event Listeners: Handle search, filters, buttons, and cart interactions.\",\"Template Literals: Generate dynamic HTML.\",\"JSON: Convert JavaScript data into a format that can be stored.\",\"LocalStorage: Save cart data in the browser and restore it after refreshing the page.\",\"Conditional Statements: Handle product availability and cart conditions.\",\"Functions: Organize our code into reusable functions.\"]}},{\"id\":\"VKc04j31Ki\",\"type\":\"header\",\"data\":{\"text\":\"Features We Are Going to Build\",\"level\":3}},{\"id\":\"78THWBqWXl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is what our final product page will include:\"}},{\"id\":\"TovOQjyRhL\",\"type\":\"paragraph\",\"data\":{\"text\":\"FeatureWhat it doesProduct ListingDisplays all available productsSearch ProductsSearches products by nameCategory FilterFilters products by categoryMinimum PriceShows products above a selected priceMaximum PriceShows products below a selected priceRating FilterDisplays products with a minimum ratingStock FilterShows only products that are in stockSortingSorts products by price or ratingAdd to CartAdds a product to the shopping cartQuantity ManagementIncreases or decreases product quantityRemove ProductRemoves an item from the cartCart TotalCalculates the total shopping amountLocalStorageSaves cart data after page refreshReset FiltersResets all product filters\"}},{\"id\":\"hi6Kf2NuUL\",\"type\":\"header\",\"data\":{\"text\":\"1. What Are We Building?\",\"level\":2}},{\"id\":\"FZgk8BcAmI\",\"type\":\"paragraph\",\"data\":{\"text\":\"We are going to build a simple e-commerce product listing page.\"}},{\"id\":\"o3jK3pU7WK\",\"type\":\"paragraph\",\"data\":{\"text\":\"Imagine a customer visits an online shopping website. The customer can:\"}},{\"id\":\"iJZAKoPDs4\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"See all available products.\",\"Search for a specific product.\",\"Select a category such as Electronics or Fashion.\",\"Set a minimum and maximum price.\",\"Filter products by rating.\",\"See only products that are in stock.\",\"Sort products from low price to high price.\",\"Add products to the cart.\",\"Increase or decrease product quantities.\",\"Refresh the browser without losing the cart.\"]}},{\"id\":\"c9OXnhc9cV\",\"type\":\"paragraph\",\"data\":{\"text\":\"All these operations will happen using JavaScript.\"}},{\"id\":\"ccMWz4TCut\",\"type\":\"paragraph\",\"data\":{\"text\":\"Important: We are building a frontend learning project. LocalStorage is not a replacement for a real shopping website's backend, database, or payment system.\"}},{\"id\":\"HEibkyRVPO\",\"type\":\"header\",\"data\":{\"text\":\"2. Project Folder Structure\",\"level\":2}},{\"id\":\"9AgqSRF59o\",\"type\":\"paragraph\",\"data\":{\"text\":\"Create a folder named \"}},{\"id\":\"CmNdoRB4Ft\",\"type\":\"code\",\"data\":{\"code\":\"javascript-ecommerce-project\",\"language\":\"\",\"raw\":true}},{\"id\":\"7b5k-djJLr\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"TfUDVbGeMs\",\"type\":\"paragraph\",\"data\":{\"text\":\"Inside it, create these three files:\"}},{\"id\":\"h4SOZJZRaQ\",\"type\":\"code\",\"data\":{\"code\":\"javascript-ecommerce-project\/\\n\u2502\\n\u251c\u2500\u2500 index.html\\n\u251c\u2500\u2500 style.css\\n\u2514\u2500\u2500 script.js\",\"language\":\"\",\"raw\":true}},{\"id\":\"1Pt8uw01ni\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>index.html<\/code> contains the webpage structure.\",\"<code>style.css<\/code> contains the design.\",\"<code>script.js<\/code> contains all JavaScript functionality.\"]}},{\"id\":\"UiAibwTIq6\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can open the project using VS Code and run it with the Live Server extension.\"}},{\"id\":\"ZdZeBn6kdv\",\"type\":\"header\",\"data\":{\"text\":\"3. Create the HTML Structure\",\"level\":2}},{\"id\":\"lFNULiyqY4\",\"type\":\"paragraph\",\"data\":{\"text\":\"First, we need to create the structure of our product page.\"}},{\"id\":\"0zymIRtb4S\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open \"}},{\"id\":\"ble3UW2kSJ\",\"type\":\"code\",\"data\":{\"code\":\"index.html\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"N2KuU-TQjw\",\"type\":\"paragraph\",\"data\":{\"text\":\" and write the following code:\"}},{\"id\":\"qEhDrl9qS8\",\"type\":\"code\",\"data\":{\"code\":\"JavaScript E-commerce ProjectShopEasy\\n            Cart: 0Find ProductsAll CategoriesElectronicsFashionAccessoriesAll Ratings3+ Stars4+ Stars4.5+ Stars\\n                In-stock products only\\n            Default SortingPrice: Low to HighPrice: High to LowRating: High to LowReset FiltersOur Products0 products foundShopping CartTotal: \u20b90\\n            \\n\\n            Clear Cart\\n\\n        \\n\\n    \\n\\n    \\n\\n\\n\",\"language\":\"html\",\"raw\":true}},{\"id\":\"WRd9E1VU0n\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the HTML\",\"level\":3}},{\"id\":\"Vs6ujaNJe2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's understand the important parts.\"}},{\"id\":\"zx5_01g_Dk\",\"type\":\"paragraph\",\"data\":{\"text\":\"1. Search input\"}},{\"id\":\"w7xO7CZ-Kc\",\"type\":\"code\",\"data\":{\"code\":\"\",\"language\":\"html\",\"raw\":true}},{\"id\":\"ghLREqkI3O\",\"type\":\"paragraph\",\"data\":{\"text\":\"This input allows customers to search for products by name.\"}},{\"id\":\"Ag_Sx8SHil\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example, if a customer types \"}},{\"id\":\"sivsFrEGdd\",\"type\":\"code\",\"data\":{\"code\":\"Laptop\",\"language\":\"\",\"raw\":true}},{\"id\":\"BZFq-id6Dk\",\"type\":\"paragraph\",\"data\":{\"text\":\", JavaScript will display matching laptop products.\"}},{\"id\":\"5dxq85j-8W\",\"type\":\"paragraph\",\"data\":{\"text\":\"2. Category filter\"}},{\"id\":\"nJACYdgjGR\",\"type\":\"code\",\"data\":{\"code\":\"\\n    All Categories\\n    Electronics\\n    Fashion\\n\",\"language\":\"html\",\"raw\":true}},{\"id\":\"rHdiScH7nK\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"_WiNuYZylz\",\"type\":\"code\",\"data\":{\"code\":\"select\",\"language\":\"sql\",\"raw\":true}},{\"id\":\"5Cu2zn7V99\",\"type\":\"paragraph\",\"data\":{\"text\":\" element creates a dropdown.\"}},{\"id\":\"zhDlNQrIgu\",\"type\":\"paragraph\",\"data\":{\"text\":\"When a customer selects Electronics, we will display only products belonging to that category.\"}},{\"id\":\"Zf_Vj5z9RB\",\"type\":\"paragraph\",\"data\":{\"text\":\"3. Price filter\"}},{\"id\":\"FV6BTZ9pJ4\",\"type\":\"code\",\"data\":{\"code\":\"\\n\",\"language\":\"html\",\"raw\":true}},{\"id\":\"pS9iGG_t_4\",\"type\":\"paragraph\",\"data\":{\"text\":\"These inputs allow customers to enter a minimum and maximum price.\"}},{\"id\":\"zk9u19IaQR\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"D3ZtUSDPxq\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Minimum price: 500\",\"Maximum price: 2000\"]}},{\"id\":\"ZSIqke0f7E\",\"type\":\"paragraph\",\"data\":{\"text\":\"The page should display products priced between \u20b9500 and \u20b92,000.\"}},{\"id\":\"wP-4CWVGTW\",\"type\":\"paragraph\",\"data\":{\"text\":\"4. Product list\"}},{\"id\":\"w7VCEKVHJZ\",\"type\":\"code\",\"data\":{\"code\":\"\",\"language\":\"html\",\"raw\":true}},{\"id\":\"ciubaTDmkm\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is an empty container.\"}},{\"id\":\"_HCg8vaymC\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript will generate product cards and insert them into this container dynamically.\"}},{\"id\":\"Ytse8heVFf\",\"type\":\"paragraph\",\"data\":{\"text\":\"5. Shopping cart\"}},{\"id\":\"FoWhosSDHv\",\"type\":\"code\",\"data\":{\"code\":\"\",\"language\":\"html\",\"raw\":true}},{\"id\":\"Vh5wB7DrHr\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript will display the products added to the cart inside this element.\"}},{\"id\":\"mLD6I0IPk3\",\"type\":\"header\",\"data\":{\"text\":\"4. Add CSS Styling\",\"level\":2}},{\"id\":\"B_7mTv7eu4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now open \"}},{\"id\":\"jIUhDvN4sJ\",\"type\":\"code\",\"data\":{\"code\":\"style.css\",\"language\":\"\",\"raw\":true}},{\"id\":\"xm_ckTvp6E\",\"type\":\"paragraph\",\"data\":{\"text\":\" and add the following code.\"}},{\"id\":\"83spop6PSg\",\"type\":\"code\",\"data\":{\"code\":\"* {\\n    margin: 0;\\n    padding: 0;\\n    box-sizing: border-box;\\n}\\n\\nbody {\\n    font-family: Arial, sans-serif;\\n    background: #f5f6fa;\\n    color: #222;\\n}\\n\\n.header {\\n    background: #172554;\\n    color: white;\\n    padding: 20px 5%;\\n    display: flex;\\n    justify-content: space-between;\\n    align-items: center;\\n}\\n\\n.cart-indicator {\\n    background: white;\\n    color: #172554;\\n    padding: 10px 16px;\\n    border-radius: 6px;\\n    font-weight: bold;\\n}\\n\\n.container {\\n    width: 90%;\\n    max-width: 1200px;\\n    margin: 30px auto;\\n}\\n\\n.filters {\\n    background: white;\\n    padding: 20px;\\n    border-radius: 10px;\\n    margin-bottom: 30px;\\n    display: grid;\\n    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));\\n    gap: 12px;\\n    align-items: center;\\n}\\n\\n.filters h2 {\\n    grid-column: 1 \/ -1;\\n}\\n\\n.filters input,\\n.filters select,\\n.filters button {\\n    width: 100%;\\n    padding: 12px;\\n    border: 1px solid #ddd;\\n    border-radius: 6px;\\n    font-size: 14px;\\n}\\n\\n.price-filter {\\n    display: flex;\\n    gap: 8px;\\n}\\n\\n.stock-option {\\n    display: flex;\\n    align-items: center;\\n    gap: 8px;\\n    font-size: 14px;\\n}\\n\\n.stock-option input {\\n    width: auto;\\n}\\n\\nbutton {\\n    cursor: pointer;\\n    border: none;\\n}\\n\\n#reset-filters,\\n#clear-cart {\\n    background: #172554;\\n    color: white;\\n}\\n\\n.product-section {\\n    margin-bottom: 40px;\\n}\\n\\n.section-heading {\\n    display: flex;\\n    justify-content: space-between;\\n    align-items: center;\\n    margin-bottom: 20px;\\n}\\n\\n.product-grid {\\n    display: grid;\\n    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));\\n    gap: 20px;\\n}\\n\\n.product-card {\\n    background: white;\\n    border-radius: 10px;\\n    padding: 18px;\\n    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.06);\\n}\\n\\n.product-image {\\n    height: 130px;\\n    display: grid;\\n    place-items: center;\\n    background: #eef2ff;\\n    font-size: 55px;\\n    border-radius: 8px;\\n    margin-bottom: 15px;\\n}\\n\\n.product-card h3 {\\n    margin-bottom: 10px;\\n}\\n\\n.product-card p {\\n    margin: 8px 0;\\n    color: #555;\\n}\\n\\n.product-card button {\\n    width: 100%;\\n    background: #2563eb;\\n    color: white;\\n    padding: 11px;\\n    border-radius: 6px;\\n    margin-top: 10px;\\n}\\n\\n.product-card button:disabled {\\n    background: #999;\\n    cursor: not-allowed;\\n}\\n\\n.cart-section {\\n    background: white;\\n    padding: 20px;\\n    border-radius: 10px;\\n    margin-bottom: 40px;\\n}\\n\\n.cart-item {\\n    display: flex;\\n    justify-content: space-between;\\n    align-items: center;\\n    gap: 15px;\\n    border-bottom: 1px solid #eee;\\n    padding: 15px 0;\\n}\\n\\n.cart-actions {\\n    display: flex;\\n    align-items: center;\\n    gap: 10px;\\n}\\n\\n.cart-actions button {\\n    padding: 7px 12px;\\n    background: #e2e8f0;\\n    border-radius: 5px;\\n}\\n\\n.cart-actions .remove-button {\\n    background: #fee2e2;\\n    color: #b91c1c;\\n}\\n\\n.cart-total {\\n    text-align: right;\\n    margin: 20px 0;\\n}\\n\\n.empty-message {\\n    padding: 20px;\\n    color: #777;\\n    text-align: center;\\n    background: #f8fafc;\\n    border-radius: 8px;\\n}\\n\\n@media (max-width: 600px) {\\n    .header {\\n        padding: 15px;\\n    }\\n\\n    .container {\\n        width: 94%;\\n    }\\n\\n    .section-heading {\\n        align-items: flex-start;\\n        flex-direction: column;\\n        gap: 8px;\\n    }\\n\\n    .cart-item {\\n        align-items: flex-start;\\n        flex-direction: column;\\n    }\\n\\n    .price-filter {\\n        flex-direction: column;\\n    }\\n}\",\"language\":\"css\",\"raw\":true}},{\"id\":\"9priYNmIaB\",\"type\":\"header\",\"data\":{\"text\":\"What Does CSS Grid Do Here?\",\"level\":3}},{\"id\":\"L1f2VQfGwC\",\"type\":\"code\",\"data\":{\"code\":\".product-grid {\\n    display: grid;\\n    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));\\n    gap: 20px;\\n}\",\"language\":\"css\",\"raw\":true}},{\"id\":\"6ZhmYqQ93Y\",\"type\":\"paragraph\",\"data\":{\"text\":\"This CSS creates a responsive product layout.\"}},{\"id\":\"ZAg5Q1iP4N\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>display: grid<\/code> enables CSS Grid.\",\"<code>minmax(220px, 1fr)<\/code> gives each product card a minimum width of 220px while allowing it to grow.\",\"<code>auto-fit<\/code> adjusts the number of columns according to available space.\",\"<code>gap: 20px<\/code> creates space between product cards.\"]}},{\"id\":\"-vfojc2GuC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's build the actual JavaScript functionality.\"}},{\"id\":\"v_SQI17_xn\",\"type\":\"header\",\"data\":{\"text\":\"5. Create Product Data Using JavaScript Objects\",\"level\":2}},{\"id\":\"Py3Ycs6rIu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Open \"}},{\"id\":\"L_sDAFBgvh\",\"type\":\"code\",\"data\":{\"code\":\"script.js\",\"language\":\"\",\"raw\":true}},{\"id\":\"YpIElBGPhn\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"rDsgLK4CuT\",\"type\":\"paragraph\",\"data\":{\"text\":\"First, we need some products to display.\"}},{\"id\":\"ajCzu3Zgji\",\"type\":\"code\",\"data\":{\"code\":\"const products = [\\n    {\\n        id: 1,\\n        name: \\\"Wireless Headphones\\\",\\n        price: 1499,\\n        category: \\\"Electronics\\\",\\n        rating: 4.5,\\n        inStock: true,\\n        image: \\\"\ud83c\udfa7\\\"\\n    },\\n    {\\n        id: 2,\\n        name: \\\"Smart Watch\\\",\\n        price: 2499,\\n        category: \\\"Electronics\\\",\\n        rating: 4.2,\\n        inStock: true,\\n        image: \\\"\u231a\\\"\\n    },\\n    {\\n        id: 3,\\n        name: \\\"Running Shoes\\\",\\n        price: 1999,\\n        category: \\\"Fashion\\\",\\n        rating: 4.7,\\n        inStock: true,\\n        image: \\\"\ud83d\udc5f\\\"\\n    },\\n    {\\n        id: 4,\\n        name: \\\"Casual T-Shirt\\\",\\n        price: 599,\\n        category: \\\"Fashion\\\",\\n        rating: 4.0,\\n        inStock: false,\\n        image: \\\"\ud83d\udc55\\\"\\n    },\\n    {\\n        id: 5,\\n        name: \\\"Laptop\\\",\\n        price: 45999,\\n        category: \\\"Electronics\\\",\\n        rating: 4.8,\\n        inStock: true,\\n        image: \\\"\ud83d\udcbb\\\"\\n    },\\n    {\\n        id: 6,\\n        name: \\\"Backpack\\\",\\n        price: 1299,\\n        category: \\\"Accessories\\\",\\n        rating: 4.1,\\n        inStock: true,\\n        image: \\\"\ud83c\udf92\\\"\\n    },\\n    {\\n        id: 7,\\n        name: \\\"Sunglasses\\\",\\n        price: 899,\\n        category: \\\"Accessories\\\",\\n        rating: 3.9,\\n        inStock: true,\\n        image: \\\"\ud83d\udd76\ufe0f\\\"\\n    },\\n    {\\n        id: 8,\\n        name: \\\"Bluetooth Speaker\\\",\\n        price: 1799,\\n        category: \\\"Electronics\\\",\\n        rating: 4.3,\\n        inStock: false,\\n        image: \\\"\ud83d\udd0a\\\"\\n    },\\n    {\\n        id: 9,\\n        name: \\\"Denim Jacket\\\",\\n        price: 2299,\\n        category: \\\"Fashion\\\",\\n        rating: 4.6,\\n        inStock: true,\\n        image: \\\"\ud83e\udde5\\\"\\n    },\\n    {\\n        id: 10,\\n        name: \\\"Leather Wallet\\\",\\n        price: 799,\\n        category: \\\"Accessories\\\",\\n        rating: 4.4,\\n        inStock: true,\\n        image: \\\"\ud83d\udc5b\\\"\\n    },\\n    {\\n        id: 11,\\n        name: \\\"Gaming Mouse\\\",\\n        price: 999,\\n        category: \\\"Electronics\\\",\\n        rating: 4.5,\\n        inStock: true,\\n        image: \\\"\ud83d\uddb1\ufe0f\\\"\\n    },\\n    {\\n        id: 12,\\n        name: \\\"Sports Cap\\\",\\n        price: 499,\\n        category: \\\"Fashion\\\",\\n        rating: 3.8,\\n        inStock: true,\\n        image: \\\"\ud83e\udde2\\\"\\n    }\\n];\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"86BBrQcF59\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Product Array\",\"level\":3}},{\"id\":\"xt5oyFaZxB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's understand one product:\"}},{\"id\":\"iDQeV682oL\",\"type\":\"code\",\"data\":{\"code\":\"{\\n    id: 1,\\n    name: \\\"Wireless Headphones\\\",\\n    price: 1499,\\n    category: \\\"Electronics\\\",\\n    rating: 4.5,\\n    inStock: true,\\n    image: \\\"\ud83c\udfa7\\\"\\n}\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"kIM2YPXbAg\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is a JavaScript object.\"}},{\"id\":\"6VANasyf6N\",\"type\":\"paragraph\",\"data\":{\"text\":\"Each property stores a different piece of information:\"}},{\"id\":\"k9wJqtPaO1\",\"type\":\"paragraph\",\"data\":{\"text\":\"PropertyPurpose\"}},{\"id\":\"2inRhpAqFy\",\"type\":\"code\",\"data\":{\"code\":\"id\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"g13rC-vtTI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unique product identification\"}},{\"id\":\"SkBe3Ndl13\",\"type\":\"code\",\"data\":{\"code\":\"name\",\"language\":\"\",\"raw\":true}},{\"id\":\"BYiDu2VMpm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Product name\"}},{\"id\":\"WpkGt85oGh\",\"type\":\"code\",\"data\":{\"code\":\"price\",\"language\":\"\",\"raw\":true}},{\"id\":\"Mp96xOIp3X\",\"type\":\"paragraph\",\"data\":{\"text\":\"Product price\"}},{\"id\":\"Ypqa0SyW9v\",\"type\":\"code\",\"data\":{\"code\":\"category\",\"language\":\"\",\"raw\":true}},{\"id\":\"e8acChRC2x\",\"type\":\"paragraph\",\"data\":{\"text\":\"Product category\"}},{\"id\":\"BGq-20vAAE\",\"type\":\"code\",\"data\":{\"code\":\"rating\",\"language\":\"\",\"raw\":true}},{\"id\":\"Przo80G1wA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Customer rating\"}},{\"id\":\"MxwgHvSE49\",\"type\":\"code\",\"data\":{\"code\":\"inStock\",\"language\":\"\",\"raw\":true}},{\"id\":\"okqr0Kk5ej\",\"type\":\"paragraph\",\"data\":{\"text\":\"Product availability\"}},{\"id\":\"mzDadGlnsT\",\"type\":\"code\",\"data\":{\"code\":\"image\",\"language\":\"\",\"raw\":true}},{\"id\":\"s9ny0hVbBD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Product image representation\"}},{\"id\":\"KGRFqpEiNO\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why are we using an array of objects?\"}},{\"id\":\"ro4Vy9EKw1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because an e-commerce website contains multiple products, and each product has multiple properties.\"}},{\"id\":\"MDMEvqcB-R\",\"type\":\"paragraph\",\"data\":{\"text\":\"An array allows us to store all products in one place and use JavaScript methods to search, filter, sort, and find them.\"}},{\"id\":\"-_hOAd4LND\",\"type\":\"paragraph\",\"data\":{\"text\":\"For this learning project, emojis represent product images. You can replace them with real image URLs later.\"}},{\"id\":\"f-LpXpdhqQ\",\"type\":\"header\",\"data\":{\"text\":\"6. Select HTML Elements Using JavaScript\",\"level\":2}},{\"id\":\"3EcuvV0i5e\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before implementing functionality, we need to access the HTML elements.\"}},{\"id\":\"OY6rl9oT4a\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this below the products array:\"}},{\"id\":\"G4825TrdmZ\",\"type\":\"code\",\"data\":{\"code\":\"const productList = document.getElementById(\\\"product-list\\\");\\n\\nconst searchInput = document.getElementById(\\\"search-input\\\");\\n\\nconst categoryFilter = document.getElementById(\\\"category-filter\\\");\\n\\nconst minPriceInput = document.getElementById(\\\"min-price\\\");\\n\\nconst maxPriceInput = document.getElementById(\\\"max-price\\\");\\n\\nconst ratingFilter = document.getElementById(\\\"rating-filter\\\");\\n\\nconst stockFilter = document.getElementById(\\\"stock-filter\\\");\\n\\nconst sortFilter = document.getElementById(\\\"sort-filter\\\");\\n\\nconst productCount = document.getElementById(\\\"product-count\\\");\\n\\nconst cartItems = document.getElementById(\\\"cart-items\\\");\\n\\nconst cartCount = document.getElementById(\\\"cart-count\\\");\\n\\nconst cartTotal = document.getElementById(\\\"cart-total\\\");\\n\\nconst resetFiltersButton = document.getElementById(\\\"reset-filters\\\");\\n\\nconst clearCartButton = document.getElementById(\\\"clear-cart\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"i6UJuMNsoY\",\"type\":\"paragraph\",\"data\":{\"text\":\"What Is \"}},{\"id\":\"oBgCTSsIOJ\",\"type\":\"code\",\"data\":{\"code\":\"getElementById()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"fMN_bVEyWy\",\"type\":\"code\",\"data\":{\"code\":\"document.getElementById()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Z3x1Otymfd\",\"type\":\"paragraph\",\"data\":{\"text\":\" is a DOM method that selects an HTML element using its ID.\"}},{\"id\":\"sTRpEoYSeV\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"xDoJ9iLAeS\",\"type\":\"code\",\"data\":{\"code\":\"const searchInput = document.getElementById(\\\"search-input\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"r9jE7ibk5R\",\"type\":\"paragraph\",\"data\":{\"text\":\"Our HTML contains:\"}},{\"id\":\"oMzRHvOrVe\",\"type\":\"code\",\"data\":{\"code\":\"\",\"language\":\"html\",\"raw\":true}},{\"id\":\"sAIQfURl83\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript finds that element and stores its reference inside the \"}},{\"id\":\"1vDm4qcu0f\",\"type\":\"code\",\"data\":{\"code\":\"searchInput\",\"language\":\"\",\"raw\":true}},{\"id\":\"qKBq6OMnf1\",\"type\":\"paragraph\",\"data\":{\"text\":\" variable.\"}},{\"id\":\"W-921iIhgW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now we can read its value and listen for user interactions.\"}},{\"id\":\"N4PDAUEmDO\",\"type\":\"header\",\"data\":{\"text\":\"7. Display Products Dynamically\",\"level\":2}},{\"id\":\"jnNg9lIMhq\",\"type\":\"paragraph\",\"data\":{\"text\":\"We have product data, but we cannot see the products on the webpage yet.\"}},{\"id\":\"5XUlO-eW5M\",\"type\":\"paragraph\",\"data\":{\"text\":\"We need to create a function that generates product cards.\"}},{\"id\":\"UJsIxcratf\",\"type\":\"code\",\"data\":{\"code\":\"function displayProducts(productArray) {\\n\\n    productList.innerHTML = \\\"\\\";\\n\\n    if (productArray.length === 0) {\\n        productList.innerHTML =\\n            'No products found.';\\n\\n        return;\\n    }\\n\\n    productArray.forEach(function(product) {\\n\\n        const productCard = document.createElement(\\\"div\\\");\\n\\n        productCard.className = \\\"product-card\\\";\\n\\n        const image = document.createElement(\\\"div\\\");\\n        image.className = \\\"product-image\\\";\\n        image.textContent = product.image;\\n\\n        const name = document.createElement(\\\"h3\\\");\\n        name.textContent = product.name;\\n\\n        const price = document.createElement(\\\"p\\\");\\n        price.textContent = `Price: \u20b9${product.price}`;\\n\\n        const category = document.createElement(\\\"p\\\");\\n        category.textContent = `Category: ${product.category}`;\\n\\n        const rating = document.createElement(\\\"p\\\");\\n        rating.textContent = `Rating: \u2b50 ${product.rating}`;\\n\\n        const stock = document.createElement(\\\"p\\\");\\n        stock.textContent = product.inStock\\n            ? \\\"In Stock\\\"\\n            : \\\"Out of Stock\\\";\\n\\n        const button = document.createElement(\\\"button\\\");\\n\\n        button.textContent = product.inStock\\n            ? \\\"Add to Cart\\\"\\n            : \\\"Out of Stock\\\";\\n\\n        button.dataset.id = product.id;\\n\\n        button.disabled = !product.inStock;\\n\\n        productCard.append(\\n            image,\\n            name,\\n            price,\\n            category,\\n            rating,\\n            stock,\\n            button\\n        );\\n\\n        productList.appendChild(productCard);\\n\\n    });\\n\\n    productCount.textContent =\\n        `${productArray.length} products found`;\\n}\",\"language\":\"html\",\"raw\":true}},{\"id\":\"ePzX8Rc_5E\",\"type\":\"paragraph\",\"data\":{\"text\":\"Understanding \"}},{\"id\":\"NjmIeCmdFm\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Gto_vz_pHg\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"7gduxp-pU-\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"-nOqfYuyrX\",\"type\":\"paragraph\",\"data\":{\"text\":\" method runs a function once for every item in an array.\"}},{\"id\":\"pJuS7WczJA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"wxEpvaLsIL\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30];\\n\\nnumbers.forEach(function(number) {\\n    console.log(number);\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"K0GrgjoHqk\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"M0eGqkR87b\",\"type\":\"code\",\"data\":{\"code\":\"10\\n20\\n30\",\"language\":\"\",\"raw\":true}},{\"id\":\"_gKjvu8xm_\",\"type\":\"paragraph\",\"data\":{\"text\":\"In our project:\"}},{\"id\":\"K8PXBzbyxV\",\"type\":\"code\",\"data\":{\"code\":\"productArray.forEach(function(product) {\\n    \/\/ Create product card\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"JjUlmpcdko\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript visits each product object and creates its product card.\"}},{\"id\":\"jduJp1mYCA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why Do We Use \"}},{\"id\":\"cQvOxPgbxq\",\"type\":\"code\",\"data\":{\"code\":\"innerHTML = \\\"\\\"\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"ObvBRAo3GY\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"pDRDWViuRu\",\"type\":\"code\",\"data\":{\"code\":\"productList.innerHTML = \\\"\\\";\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"OoRBM7G9ZI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Every time we display products, we clear the previous product cards.\"}},{\"id\":\"czDZL-k6uf\",\"type\":\"paragraph\",\"data\":{\"text\":\"Otherwise, when we search or apply a filter, the old cards may remain and new cards may be added below them.\"}},{\"id\":\"eTUM0oPA6l\",\"type\":\"paragraph\",\"data\":{\"text\":\"We want to replace the previous product list with the newly filtered result.\"}},{\"id\":\"iXohsqk2TF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why Do We Use \"}},{\"id\":\"AKEcVdRRjG\",\"type\":\"code\",\"data\":{\"code\":\"textContent\",\"language\":\"\",\"raw\":true}},{\"id\":\"abktwpB4Z4\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"eKRAKobMyD\",\"type\":\"code\",\"data\":{\"code\":\"name.textContent = product.name;\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"kmzk22kALJ\",\"type\":\"code\",\"data\":{\"code\":\"textContent\",\"language\":\"\",\"raw\":true}},{\"id\":\"IcB5nTarox\",\"type\":\"paragraph\",\"data\":{\"text\":\" inserts text into an element.\"}},{\"id\":\"7LWbFIlh5d\",\"type\":\"paragraph\",\"data\":{\"text\":\"It is a safer choice when displaying dynamic text because it does not interpret the value as HTML.\"}},{\"id\":\"X7QmvjCVog\",\"type\":\"header\",\"data\":{\"text\":\"8. Implement Product Search\",\"level\":2}},{\"id\":\"rVcIugYeyY\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's implement the search functionality.\"}},{\"id\":\"dIq5TjmC4e\",\"type\":\"paragraph\",\"data\":{\"text\":\"A customer should be able to type a product name and see matching results.\"}},{\"id\":\"2RUj0I1nDZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this function:\"}},{\"id\":\"IKA9yBjYJN\",\"type\":\"code\",\"data\":{\"code\":\"function searchProducts(productArray) {\\n\\n    const searchTerm = searchInput.value.toLowerCase().trim();\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.name\\n            .toLowerCase()\\n            .includes(searchTerm);\\n\\n    });\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"wMfRPp00MW\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Search Logic\",\"level\":3}},{\"id\":\"rruI0cq89t\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose we have:\"}},{\"id\":\"lnGCqiSmB-\",\"type\":\"code\",\"data\":{\"code\":\"const productName = \\\"Wireless Headphones\\\";\\n\\nconst searchTerm = \\\"wireless\\\";\\n\\nconsole.log(\\n    productName.toLowerCase().includes(searchTerm)\\n);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"enQgiJH2uP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"l1cALpfio1\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"LK-4KuP5YZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why?\"}},{\"id\":\"zRymJUduSx\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>toLowerCase()<\/code> converts the product name into lowercase.\",\"<code>includes()<\/code> checks whether the search term exists inside the product name.\"]}},{\"id\":\"a3D-Oj4Po-\",\"type\":\"paragraph\",\"data\":{\"text\":\"We use \"}},{\"id\":\"ic1NkWXm-B\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ui8yHa8d2P\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example, searching for \"}},{\"id\":\"Htp2924fCY\",\"type\":\"code\",\"data\":{\"code\":\"headphones\",\"language\":\"\",\"raw\":true}},{\"id\":\"MO0sMHOdPf\",\"type\":\"paragraph\",\"data\":{\"text\":\" should return the Wireless Headphones product.\"}},{\"id\":\"ytoccwI9St\",\"type\":\"header\",\"data\":{\"text\":\"9. Implement Category Filtering\",\"level\":2}},{\"id\":\"2X--5v052X\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's allow customers to filter products by category.\"}},{\"id\":\"8ywgJlJkwo\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this function:\"}},{\"id\":\"83nCpH233_\",\"type\":\"code\",\"data\":{\"code\":\"function filterByCategory(productArray) {\\n\\n    const selectedCategory = categoryFilter.value;\\n\\n    return productArray.filter(function(product) {\\n\\n        if (selectedCategory === \\\"all\\\") {\\n            return true;\\n        }\\n\\n        return product.category === selectedCategory;\\n\\n    });\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"YijkTBoiQY\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Category Filter\",\"level\":3}},{\"id\":\"eOXIbLA_5G\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose a customer selects:\"}},{\"id\":\"Dkoz-9Jaft\",\"type\":\"code\",\"data\":{\"code\":\"Electronics\",\"language\":\"\",\"raw\":true}},{\"id\":\"FX6Pd4_2ML\",\"type\":\"paragraph\",\"data\":{\"text\":\"Our JavaScript checks:\"}},{\"id\":\"NzVvnnSqTI\",\"type\":\"code\",\"data\":{\"code\":\"product.category === selectedCategory\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"uPFVfTNB6P\",\"type\":\"paragraph\",\"data\":{\"text\":\"If the product category is Electronics, the condition returns \"}},{\"id\":\"U3bIoUksY5\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"EbY1Sup0Hb\",\"type\":\"paragraph\",\"data\":{\"text\":\"If the category is Fashion, it returns \"}},{\"id\":\"4ebv993I3y\",\"type\":\"code\",\"data\":{\"code\":\"false\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"k9RgQgmu2Q\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"p7tCk8gabl\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"oSEflcroCV\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns only the products for which the callback returns \"}},{\"id\":\"dBECpG35nL\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"aZovGmDZva\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why do we return \"}},{\"id\":\"ybm6JqXMK5\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"Dt0njVwxrS\",\"type\":\"paragraph\",\"data\":{\"text\":\" when the selected category is \"}},{\"id\":\"yJ54oxrfvX\",\"type\":\"code\",\"data\":{\"code\":\"\\\"all\\\"\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"1Uzu0ZmyTk\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"KfYJ0YMk2p\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because the customer wants to see every product, regardless of category.\"}},{\"id\":\"bU878hS1WC\",\"type\":\"header\",\"data\":{\"text\":\"10. Implement Minimum and Maximum Price Filtering\",\"level\":2}},{\"id\":\"e27p1pFw_7\",\"type\":\"paragraph\",\"data\":{\"text\":\"A shopping website should allow customers to search within a price range.\"}},{\"id\":\"TceK-p-bpo\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"I_AAY-VcMo\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Minimum price: \u20b9500\",\"Maximum price: \u20b92,000\"]}},{\"id\":\"re4Ux05V_q\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this function:\"}},{\"id\":\"t42mHj3j2g\",\"type\":\"code\",\"data\":{\"code\":\"function filterByPrice(productArray) {\\n\\n    const minPrice = minPriceInput.value;\\n\\n    const maxPrice = maxPriceInput.value;\\n\\n    return productArray.filter(function(product) {\\n\\n        const matchesMinPrice =\\n            minPrice === \\\"\\\" ||\\n            product.price &gt;= Number(minPrice);\\n\\n        const matchesMaxPrice =\\n            maxPrice === \\\"\\\" ||\\n            product.price &lt;= Number(maxPrice);\\n\\n        return matchesMinPrice &amp;&amp; matchesMaxPrice;\\n\\n    });\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"fxrZ-qFPqR\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Minimum Price Condition\",\"level\":3}},{\"id\":\"fhOm7Ba31Z\",\"type\":\"code\",\"data\":{\"code\":\"minPrice === \\\"\\\" ||\\nproduct.price &gt;= Number(minPrice)\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"z54Y96Gc_w\",\"type\":\"paragraph\",\"data\":{\"text\":\"This means:\"}},{\"id\":\"jTzYVsxbC1\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"If the minimum price is empty, do not restrict the product by minimum price.\",\"Otherwise, display products whose price is greater than or equal to the entered minimum.\"]}},{\"id\":\"buuHotI9Wi\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why do we use \"}},{\"id\":\"IMwU8SzISh\",\"type\":\"code\",\"data\":{\"code\":\"Number()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"uWU2xz6siL\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"-xF6iuY7cv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because input values are generally read as strings.\"}},{\"id\":\"luuftz-hWA\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"BuIx5w7NsW\",\"type\":\"code\",\"data\":{\"code\":\"const price = \\\"1000\\\";\\n\\nconsole.log(typeof price);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"A9NilKZ_2K\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"yX54J1cJHP\",\"type\":\"code\",\"data\":{\"code\":\"string\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"dszGEmhSOg\",\"type\":\"paragraph\",\"data\":{\"text\":\"But product prices are numbers.\"}},{\"id\":\"oG40_O7Uq9\",\"type\":\"paragraph\",\"data\":{\"text\":\"Therefore, we convert the input value:\"}},{\"id\":\"Op4R3_q30s\",\"type\":\"code\",\"data\":{\"code\":\"Number(minPrice)\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"d15ox9XiWu\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Maximum Price Condition\",\"level\":3}},{\"id\":\"9KE7iYlw9X\",\"type\":\"code\",\"data\":{\"code\":\"product.price &lt;= Number(maxPrice)\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"pylpk-X_R6\",\"type\":\"paragraph\",\"data\":{\"text\":\"This checks whether the product price is less than or equal to the maximum price.\"}},{\"id\":\"OzLKa6dKaN\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why Do We Use \"}},{\"id\":\"ONwhRNR7vD\",\"type\":\"code\",\"data\":{\"code\":\"&amp;&amp;\",\"language\":\"xml\",\"raw\":true}},{\"id\":\"Aj3YFbn4Ee\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"-zszWxIjsX\",\"type\":\"code\",\"data\":{\"code\":\"return matchesMinPrice &amp;&amp; matchesMaxPrice;\",\"language\":\"kotlin\",\"raw\":true}},{\"id\":\"1c0ks63eYr\",\"type\":\"paragraph\",\"data\":{\"text\":\"We want both conditions to be true.\"}},{\"id\":\"9y0Ld-O2Gj\",\"type\":\"paragraph\",\"data\":{\"text\":\"A product must satisfy the minimum price and maximum price conditions to appear in the results.\"}},{\"id\":\"ElJVnZQlK8\",\"type\":\"header\",\"data\":{\"text\":\"11. Implement Rating Filtering\",\"level\":2}},{\"id\":\"WjnzZJVMIW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Customers often want products with good ratings.\"}},{\"id\":\"3Bqvf6k6gR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's add a rating filter.\"}},{\"id\":\"R9wtKJ37am\",\"type\":\"code\",\"data\":{\"code\":\"function filterByRating(productArray) {\\n\\n    const minimumRating = Number(ratingFilter.value);\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.rating &gt;= minimumRating;\\n\\n    });\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"qK1BO0jKbR\",\"type\":\"header\",\"data\":{\"text\":\"Example\",\"level\":3}},{\"id\":\"eMYlDrIHDb\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose the customer selects:\"}},{\"id\":\"da_VszR_c5\",\"type\":\"code\",\"data\":{\"code\":\"4+ Stars\",\"language\":\"\",\"raw\":true}},{\"id\":\"Y-J-_tkM9T\",\"type\":\"paragraph\",\"data\":{\"text\":\"Our code checks:\"}},{\"id\":\"DfX34xfhEN\",\"type\":\"code\",\"data\":{\"code\":\"product.rating &gt;= 4\",\"language\":\"xml\",\"raw\":true}},{\"id\":\"KYefSiWzi_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Products with ratings of 4, 4.2, 4.5, and 4.8 will be displayed.\"}},{\"id\":\"LI_mM8zwau\",\"type\":\"paragraph\",\"data\":{\"text\":\"Products with ratings below 4 will not be displayed.\"}},{\"id\":\"V-uPw9pdO2\",\"type\":\"paragraph\",\"data\":{\"text\":\"If the customer selects All Ratings, the minimum rating is zero, so every product passes this condition.\"}},{\"id\":\"dFmnbjVUxb\",\"type\":\"header\",\"data\":{\"text\":\"12. Implement In-Stock Filtering\",\"level\":2}},{\"id\":\"0b_Ijj8ger\",\"type\":\"paragraph\",\"data\":{\"text\":\"Sometimes products are unavailable.\"}},{\"id\":\"XNcQos-KkK\",\"type\":\"paragraph\",\"data\":{\"text\":\"We already have an \"}},{\"id\":\"VRtZjcgPj-\",\"type\":\"code\",\"data\":{\"code\":\"inStock\",\"language\":\"\",\"raw\":true}},{\"id\":\"Sxwrcg5T03\",\"type\":\"paragraph\",\"data\":{\"text\":\" property in our product objects.\"}},{\"id\":\"oB2hreRWJB\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"bgNDwl-bkJ\",\"type\":\"code\",\"data\":{\"code\":\"{\\n    id: 4,\\n    name: \\\"Casual T-Shirt\\\",\\n    price: 599,\\n    category: \\\"Fashion\\\",\\n    rating: 4.0,\\n    inStock: false,\\n    image: \\\"\ud83d\udc55\\\"\\n}\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"WvHl2pva7f\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now create this function:\"}},{\"id\":\"CSXQr_jXwy\",\"type\":\"code\",\"data\":{\"code\":\"function filterByStock(productArray) {\\n\\n    const onlyInStock = stockFilter.checked;\\n\\n    if (!onlyInStock) {\\n        return productArray;\\n    }\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.inStock === true;\\n\\n    });\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"bN-t281NBC\",\"type\":\"header\",\"data\":{\"text\":\"Understanding Checkbox Values\",\"level\":3}},{\"id\":\"UYWbb9FpAn\",\"type\":\"paragraph\",\"data\":{\"text\":\"For checkboxes, we use:\"}},{\"id\":\"h1bTfmYOx-\",\"type\":\"code\",\"data\":{\"code\":\"stockFilter.checked\",\"language\":\"\",\"raw\":true}},{\"id\":\"-1MIWboLBK\",\"type\":\"paragraph\",\"data\":{\"text\":\"It returns:\"}},{\"id\":\"eMP7LkGVSF\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>true<\/code> when the checkbox is selected.\",\"<code>false<\/code> when the checkbox is not selected.\"]}},{\"id\":\"olS0H_ckwo\",\"type\":\"paragraph\",\"data\":{\"text\":\"When the customer selects In-stock products only, we display products whose \"}},{\"id\":\"4iTvmAGDpj\",\"type\":\"code\",\"data\":{\"code\":\"inStock\",\"language\":\"\",\"raw\":true}},{\"id\":\"VvKr7La9NL\",\"type\":\"paragraph\",\"data\":{\"text\":\" value is \"}},{\"id\":\"Akk47HBZWG\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"T87A3uxUKg\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"itXreFig1q\",\"type\":\"header\",\"data\":{\"text\":\"13. Combine All Filters into One Function\",\"level\":2}},{\"id\":\"kHKXAD5ji6\",\"type\":\"paragraph\",\"data\":{\"text\":\"So far, we have created separate functions for:\"}},{\"id\":\"ATo7Guhi7j\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Search\",\"Category\",\"Price\",\"Rating\",\"Stock\"]}},{\"id\":\"Qndq8xBD9A\",\"type\":\"paragraph\",\"data\":{\"text\":\"But we need all filters to work together.\"}},{\"id\":\"YvIK7_o4Ox\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example, a customer might:\"}},{\"id\":\"318uKskoiE\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Search for Headphones.\",\"Select Electronics.\",\"Set a maximum price of \u20b92,000.\",\"Select a rating of 4+ stars.\",\"Select In-stock products only.\"]}},{\"id\":\"jmQrWN4SRH\",\"type\":\"paragraph\",\"data\":{\"text\":\"All these conditions should work together.\"}},{\"id\":\"_y5xngiSC_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Create this function:\"}},{\"id\":\"rCVTkfhGy5\",\"type\":\"code\",\"data\":{\"code\":\"function filterProducts() {\\n\\n    let filteredProducts = products;\\n\\n    filteredProducts = searchProducts(filteredProducts);\\n\\n    filteredProducts = filterByCategory(filteredProducts);\\n\\n    filteredProducts = filterByPrice(filteredProducts);\\n\\n    filteredProducts = filterByRating(filteredProducts);\\n\\n    filteredProducts = filterByStock(filteredProducts);\\n\\n    displayProducts(filteredProducts);\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"mTC52LzMyz\",\"type\":\"header\",\"data\":{\"text\":\"How Does This Function Work?\",\"level\":3}},{\"id\":\"01rKnlcatK\",\"type\":\"paragraph\",\"data\":{\"text\":\"Initially:\"}},{\"id\":\"hMwO5Sf7H1\",\"type\":\"code\",\"data\":{\"code\":\"let filteredProducts = products;\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"0rCwBhMyp2\",\"type\":\"paragraph\",\"data\":{\"text\":\"We start with the complete product array.\"}},{\"id\":\"FdzhYG8OUD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Then:\"}},{\"id\":\"fNylaQwCT7\",\"type\":\"code\",\"data\":{\"code\":\"filteredProducts = searchProducts(filteredProducts);\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"Djqyxdfinx\",\"type\":\"paragraph\",\"data\":{\"text\":\"Only products matching the search term remain.\"}},{\"id\":\"pdgtI1iphx\",\"type\":\"paragraph\",\"data\":{\"text\":\"Next:\"}},{\"id\":\"I8bbQ2t-lD\",\"type\":\"code\",\"data\":{\"code\":\"filteredProducts = filterByCategory(filteredProducts);\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"wX-JdW3X72\",\"type\":\"paragraph\",\"data\":{\"text\":\"We filter the remaining products by category.\"}},{\"id\":\"63K2mkhqAb\",\"type\":\"paragraph\",\"data\":{\"text\":\"The same process continues for price, rating, and stock.\"}},{\"id\":\"WtujjUbZLn\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is important: every filter receives the result of the previous filter.\"}},{\"id\":\"QL2MBgxaIe\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"5cEej3XkLW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose we have 12 products.\"}},{\"id\":\"SCMeKQVWMx\",\"type\":\"paragraph\",\"data\":{\"text\":\"OperationExample resultAll products12Search Headphones1Category Electronics1Maximum price \u20b92,0001Rating 4+1In stock only1\"}},{\"id\":\"PpfIc4XDyX\",\"type\":\"paragraph\",\"data\":{\"text\":\"The final result contains only products that satisfy every selected filter.\"}},{\"id\":\"_iB7bV8Chq\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is how multiple filters work together on a product listing page.\"}},{\"id\":\"vxdDKtEaMV\",\"type\":\"header\",\"data\":{\"text\":\"14. Implement Product Sorting\",\"level\":2}},{\"id\":\"2zI5n5YF-G\",\"type\":\"paragraph\",\"data\":{\"text\":\"Filtering and sorting are different operations.\"}},{\"id\":\"2_p356kKNI\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Filtering removes products that do not match the selected conditions.\",\"Sorting changes the order of the remaining products.\"]}},{\"id\":\"A394fq4Wp9\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example, a customer wants to see the cheapest products first.\"}},{\"id\":\"SmWz2DB9HA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Create this function:\"}},{\"id\":\"LwJ5pB4x-m\",\"type\":\"code\",\"data\":{\"code\":\"function sortProducts(productArray) {\\n\\n    const sortValue = sortFilter.value;\\n\\n    const sortedProducts = [...productArray];\\n\\n    if (sortValue === \\\"price-low\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return a.price - b.price;\\n        });\\n\\n    } else if (sortValue === \\\"price-high\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return b.price - a.price;\\n        });\\n\\n    } else if (sortValue === \\\"rating-high\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return b.rating - a.rating;\\n        });\\n\\n    }\\n\\n    return sortedProducts;\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"JpVucAbfk9\",\"type\":\"paragraph\",\"data\":{\"text\":\"Understanding \"}},{\"id\":\"MjZKUpuGOJ\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"KCGxYWV8id\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"uCWa5zvElb\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"9TW7bkgO0c\",\"type\":\"paragraph\",\"data\":{\"text\":\" method changes the order of array elements.\"}},{\"id\":\"Ayl1hB9Ws0\",\"type\":\"paragraph\",\"data\":{\"text\":\"For numbers, we can use a comparison function.\"}},{\"id\":\"bFRZI4_1GG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Low to high:\"}},{\"id\":\"jEYPJ78bb_\",\"type\":\"code\",\"data\":{\"code\":\"products.sort(function(a, b) {\\n    return a.price - b.price;\\n});\",\"language\":\"css\",\"raw\":true}},{\"id\":\"XC1NOVsLBs\",\"type\":\"paragraph\",\"data\":{\"text\":\"If \"}},{\"id\":\"e2oHgPDhLo\",\"type\":\"code\",\"data\":{\"code\":\"a.price\",\"language\":\"css\",\"raw\":true}},{\"id\":\"uWYF1SyOU1\",\"type\":\"paragraph\",\"data\":{\"text\":\" is smaller than \"}},{\"id\":\"kKwNbwfp2g\",\"type\":\"code\",\"data\":{\"code\":\"b.price\",\"language\":\"css\",\"raw\":true}},{\"id\":\"4Y39BsCu60\",\"type\":\"paragraph\",\"data\":{\"text\":\", the result is negative, so \"}},{\"id\":\"3xnl-Xp-ub\",\"type\":\"code\",\"data\":{\"code\":\"a\",\"language\":\"css\",\"raw\":true}},{\"id\":\"Jx_otYmCln\",\"type\":\"paragraph\",\"data\":{\"text\":\" comes first.\"}},{\"id\":\"TTewPCi25q\",\"type\":\"paragraph\",\"data\":{\"text\":\"High to low:\"}},{\"id\":\"LZwwEoPfyU\",\"type\":\"code\",\"data\":{\"code\":\"products.sort(function(a, b) {\\n    return b.price - a.price;\\n});\",\"language\":\"css\",\"raw\":true}},{\"id\":\"_6LDO7D0eR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now the higher-priced product comes first.\"}},{\"id\":\"_mBcD_EY2E\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why Do We Use \"}},{\"id\":\"j5VDDsC653\",\"type\":\"code\",\"data\":{\"code\":\"[...productArray]\",\"language\":\"css\",\"raw\":true}},{\"id\":\"WA35KwCYUN\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"eSnWEectBb\",\"type\":\"code\",\"data\":{\"code\":\"const sortedProducts = [...productArray];\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"gpB9WlBFMT\",\"type\":\"paragraph\",\"data\":{\"text\":\"The spread operator creates a shallow copy of the array.\"}},{\"id\":\"WbeFVLiD7X\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"-0R1FUFv9J\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"1Xo4G7maI_\",\"type\":\"paragraph\",\"data\":{\"text\":\" method modifies the original array. We do not want to change our original product data every time a customer selects a different sorting option.\"}},{\"id\":\"AI3-gnPRqt\",\"type\":\"paragraph\",\"data\":{\"text\":\"Therefore, we sort a copy.\"}},{\"id\":\"glv-Aqox-_\",\"type\":\"header\",\"data\":{\"text\":\"15. Update the Main Product Rendering Function\",\"level\":2}},{\"id\":\"cktj_HRknM\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now that we have created our filter and sorting functions, we need one function to run everything.\"}},{\"id\":\"GgYPLgyFyi\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"3Ov41JTgC1\",\"type\":\"code\",\"data\":{\"code\":\"function updateProductPage() {\\n\\n    let filteredProducts = products;\\n\\n    filteredProducts = searchProducts(filteredProducts);\\n\\n    filteredProducts = filterByCategory(filteredProducts);\\n\\n    filteredProducts = filterByPrice(filteredProducts);\\n\\n    filteredProducts = filterByRating(filteredProducts);\\n\\n    filteredProducts = filterByStock(filteredProducts);\\n\\n    const sortedProducts = sortProducts(filteredProducts);\\n\\n    displayProducts(sortedProducts);\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Fgl-1P1YSO\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is the main function responsible for updating the product listing.\"}},{\"id\":\"C2jK2mS06o\",\"type\":\"paragraph\",\"data\":{\"text\":\"Whenever a customer changes a filter or sorting option, we will call this function.\"}},{\"id\":\"ckAlwkm0so\",\"type\":\"header\",\"data\":{\"text\":\"16. Add Event Listeners to Filters\",\"level\":2}},{\"id\":\"zOoBOwyFk_\",\"type\":\"paragraph\",\"data\":{\"text\":\"We have created the filter functions, but how will JavaScript know when a customer changes a filter?\"}},{\"id\":\"LnoX5QDHpv\",\"type\":\"paragraph\",\"data\":{\"text\":\"We use event listeners.\"}},{\"id\":\"razk_zcBRU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this code:\"}},{\"id\":\"X_FKyJKp6e\",\"type\":\"code\",\"data\":{\"code\":\"searchInput.addEventListener(\\\"input\\\", updateProductPage);\\n\\ncategoryFilter.addEventListener(\\\"change\\\", updateProductPage);\\n\\nminPriceInput.addEventListener(\\\"input\\\", updateProductPage);\\n\\nmaxPriceInput.addEventListener(\\\"input\\\", updateProductPage);\\n\\nratingFilter.addEventListener(\\\"change\\\", updateProductPage);\\n\\nstockFilter.addEventListener(\\\"change\\\", updateProductPage);\\n\\nsortFilter.addEventListener(\\\"change\\\", updateProductPage);\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"vjrbj3bGYG\",\"type\":\"header\",\"data\":{\"text\":\"What Is an Event Listener?\",\"level\":3}},{\"id\":\"GIoET0tWXm\",\"type\":\"paragraph\",\"data\":{\"text\":\"An event listener waits for a particular action.\"}},{\"id\":\"XUqonCHLiU\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"7dhiG83ee1\",\"type\":\"code\",\"data\":{\"code\":\"searchInput.addEventListener(\\\"input\\\", updateProductPage);\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"Dw6cIjWupF\",\"type\":\"paragraph\",\"data\":{\"text\":\"This means whenever the customer types something in the search field, JavaScript calls \"}},{\"id\":\"4oU_sC8J4e\",\"type\":\"code\",\"data\":{\"code\":\"updateProductPage()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"R03IXSnETs\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"xFlK8tyUDe\",\"type\":\"paragraph\",\"data\":{\"text\":\"Common events used in this project:\"}},{\"id\":\"o_AQwtS2qt\",\"type\":\"paragraph\",\"data\":{\"text\":\"EventWhen it runs\"}},{\"id\":\"WugpBP2Y4r\",\"type\":\"code\",\"data\":{\"code\":\"input\",\"language\":\"css\",\"raw\":true}},{\"id\":\"oGC-P36BZD\",\"type\":\"paragraph\",\"data\":{\"text\":\"When the input value changes\"}},{\"id\":\"d-2yX--HVk\",\"type\":\"code\",\"data\":{\"code\":\"change\",\"language\":\"\",\"raw\":true}},{\"id\":\"r84tJi3ncc\",\"type\":\"paragraph\",\"data\":{\"text\":\"When a select or checkbox value changes\"}},{\"id\":\"0Je6J1rkaQ\",\"type\":\"code\",\"data\":{\"code\":\"click\",\"language\":\"\",\"raw\":true}},{\"id\":\"6-0ei3tI91\",\"type\":\"paragraph\",\"data\":{\"text\":\"When a button or element is clicked\"}},{\"id\":\"6ddcbSCw-l\",\"type\":\"header\",\"data\":{\"text\":\"17. Implement Reset Filters\",\"level\":2}},{\"id\":\"9K_tizSHJS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Customers should be able to reset all filters and see every product again.\"}},{\"id\":\"SDHPjw6xjH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"56fntdsPsD\",\"type\":\"code\",\"data\":{\"code\":\"resetFiltersButton.addEventListener(\\\"click\\\", function() {\\n\\n    searchInput.value = \\\"\\\";\\n\\n    categoryFilter.value = \\\"all\\\";\\n\\n    minPriceInput.value = \\\"\\\";\\n\\n    maxPriceInput.value = \\\"\\\";\\n\\n    ratingFilter.value = \\\"0\\\";\\n\\n    stockFilter.checked = false;\\n\\n    sortFilter.value = \\\"default\\\";\\n\\n    updateProductPage();\\n\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"uw9GWV_AYA\",\"type\":\"header\",\"data\":{\"text\":\"How Does Reset Work?\",\"level\":3}},{\"id\":\"EOazkYWALQ\",\"type\":\"paragraph\",\"data\":{\"text\":\"We are resetting every filter element to its default value.\"}},{\"id\":\"tL-8AgFiM2\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"JujBNpl3R-\",\"type\":\"code\",\"data\":{\"code\":\"searchInput.value = \\\"\\\";\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"5dvXspM9Pv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Clears the search input.\"}},{\"id\":\"T1u9gbfKxS\",\"type\":\"code\",\"data\":{\"code\":\"categoryFilter.value = \\\"all\\\";\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"4EHjpQRilu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Selects All Categories.\"}},{\"id\":\"djCdNECMz2\",\"type\":\"code\",\"data\":{\"code\":\"stockFilter.checked = false;\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"8ffp9c93Ti\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unchecks the stock checkbox.\"}},{\"id\":\"-veiA0-UpW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Finally:\"}},{\"id\":\"9VD1K2uKCn\",\"type\":\"code\",\"data\":{\"code\":\"updateProductPage();\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"V-P3q-hNTG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Refreshes the product listing using the default filter values.\"}},{\"id\":\"X-UnumNGFU\",\"type\":\"header\",\"data\":{\"text\":\"18. Create the Shopping Cart Using JavaScript\",\"level\":2}},{\"id\":\"ihR9l0tgz_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's implement the shopping cart.\"}},{\"id\":\"9DVkT3WECR\",\"type\":\"paragraph\",\"data\":{\"text\":\"We need an array to store the products added by the customer.\"}},{\"id\":\"8GXVS_XY8a\",\"type\":\"paragraph\",\"data\":{\"text\":\"We will store each cart item using its product ID and quantity.\"}},{\"id\":\"au5zmMw21O\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"pCNm7_DxDE\",\"type\":\"code\",\"data\":{\"code\":\"const cart = [\\n    {\\n        id: 1,\\n        quantity: 2\\n    },\\n    {\\n        id: 3,\\n        quantity: 1\\n    }\\n];\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"t06A1BOdtX\",\"type\":\"paragraph\",\"data\":{\"text\":\"This means:\"}},{\"id\":\"e-rGeZngOg\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Product ID 1 has a quantity of 2.\",\"Product ID 3 has a quantity of 1.\"]}},{\"id\":\"AbsdQbUhS6\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why are we storing the ID instead of duplicating the entire product object?\"}},{\"id\":\"X3W2I60iuT\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because our original \"}},{\"id\":\"V2YkY9VI6r\",\"type\":\"code\",\"data\":{\"code\":\"products\",\"language\":\"\",\"raw\":true}},{\"id\":\"AELYxjnrkK\",\"type\":\"paragraph\",\"data\":{\"text\":\" array already contains the product name, price, category, and other details.\"}},{\"id\":\"oRXtk4K0QY\",\"type\":\"paragraph\",\"data\":{\"text\":\"We can use the ID to find the original product whenever we need its information.\"}},{\"id\":\"TUQBgqEyX-\",\"type\":\"header\",\"data\":{\"text\":\"19. Save Cart Data Using LocalStorage\",\"level\":2}},{\"id\":\"Aa-kPuhQ7g\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before adding products to the cart, let's understand LocalStorage.\"}},{\"id\":\"1LIELV40az\",\"type\":\"header\",\"data\":{\"text\":\"What Is LocalStorage?\",\"level\":3}},{\"id\":\"7XcJHIoiec\",\"type\":\"paragraph\",\"data\":{\"text\":\"LocalStorage is a browser feature that allows websites to save small amounts of data as key-value pairs.\"}},{\"id\":\"ALH92rwFwV\",\"type\":\"paragraph\",\"data\":{\"text\":\"The data remains available even after the browser tab is closed or the page is refreshed, unless it is cleared by the user or browser.\"}},{\"id\":\"D99Pca8a5f\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"YQgtPkM6z1\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem(\\\"username\\\", \\\"Saif\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"PgxU1ooLGe\",\"type\":\"paragraph\",\"data\":{\"text\":\"This saves a value with the key \"}},{\"id\":\"YOKbbxVHSS\",\"type\":\"code\",\"data\":{\"code\":\"username\",\"language\":\"\",\"raw\":true}},{\"id\":\"LeaEjAj6wL\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"OCSNdnHDON\",\"type\":\"paragraph\",\"data\":{\"text\":\"To retrieve it:\"}},{\"id\":\"o8LMqiS4yY\",\"type\":\"code\",\"data\":{\"code\":\"const username = localStorage.getItem(\\\"username\\\");\\n\\nconsole.log(username);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"bwUVRtGmqr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"9ndBNkligr\",\"type\":\"code\",\"data\":{\"code\":\"Saif\",\"language\":\"\",\"raw\":true}},{\"id\":\"z4l7hBI_qo\",\"type\":\"paragraph\",\"data\":{\"text\":\"To remove a value:\"}},{\"id\":\"Lkm9Y0lqjG\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.removeItem(\\\"username\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"dHC4qyubfg\",\"type\":\"paragraph\",\"data\":{\"text\":\"To clear all LocalStorage data for the current website:\"}},{\"id\":\"PecC8ggHOP\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.clear();\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"40eBibU7WU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Important: LocalStorage stores strings. It cannot directly store JavaScript arrays or objects.\"}},{\"id\":\"UXLigdhdBY\",\"type\":\"paragraph\",\"data\":{\"text\":\"That's why we use JSON.\"}},{\"id\":\"F-9l9c7l0w\",\"type\":\"header\",\"data\":{\"text\":\"What Is JSON.stringify()?\",\"level\":3}},{\"id\":\"bBLC9Mp2St\",\"type\":\"paragraph\",\"data\":{\"text\":\"It converts JavaScript data into a JSON string.\"}},{\"id\":\"azTLILNuJB\",\"type\":\"code\",\"data\":{\"code\":\"const user = {\\n    name: \\\"Saif\\\",\\n    age: 27\\n};\\n\\nconst userString = JSON.stringify(user);\\n\\nconsole.log(userString);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"BhTksnNPDA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"kqSeMoLwo6\",\"type\":\"code\",\"data\":{\"code\":\"{\\\"name\\\":\\\"Saif\\\",\\\"age\\\":27}\",\"language\":\"json\",\"raw\":true}},{\"id\":\"FGbIswvRBE\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now we can save this string:\"}},{\"id\":\"z0R4OneBHz\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem(\\\"user\\\", userString);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"KCpOtCaLNN\",\"type\":\"header\",\"data\":{\"text\":\"What Is JSON.parse()?\",\"level\":3}},{\"id\":\"sJ8tjJKdCO\",\"type\":\"paragraph\",\"data\":{\"text\":\"It converts a JSON string back into a JavaScript value.\"}},{\"id\":\"10KrKYeEkz\",\"type\":\"code\",\"data\":{\"code\":\"const savedUser = localStorage.getItem(\\\"user\\\");\\n\\nconst userObject = JSON.parse(savedUser);\\n\\nconsole.log(userObject.name);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"FjB-hBNFz_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"5ntWQd4tTr\",\"type\":\"code\",\"data\":{\"code\":\"Saif\",\"language\":\"\",\"raw\":true}},{\"id\":\"QyQ4TZ6qXR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Remember:\"}},{\"id\":\"Z_UlJyUqZi\",\"type\":\"paragraph\",\"data\":{\"text\":\"MethodPurpose\"}},{\"id\":\"lb1kGXm2uA\",\"type\":\"code\",\"data\":{\"code\":\"JSON.stringify()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"-0ykuNkAND\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript value to JSON string\"}},{\"id\":\"cB8S6gguo_\",\"type\":\"code\",\"data\":{\"code\":\"JSON.parse()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"bP8YaRbNXj\",\"type\":\"paragraph\",\"data\":{\"text\":\"JSON string to JavaScript value\"}},{\"id\":\"iiwXfSJNav\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"ELoO0NNOee\",\"type\":\"paragraph\",\"data\":{\"text\":\"Save data\"}},{\"id\":\"S6oc8PcBHB\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.getItem()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"TgW_vh37jg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Read data\"}},{\"id\":\"ufosh_7Ho9\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.removeItem()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"oXLrfN7pxX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Remove a stored key\"}},{\"id\":\"knodfaPRAh\",\"type\":\"header\",\"data\":{\"text\":\"20. Load Cart Data from LocalStorage\",\"level\":2}},{\"id\":\"C6hvb1FE7a\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's load previously saved cart data when the website opens.\"}},{\"id\":\"I6azmjwz21\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"no4COI7RZF\",\"type\":\"code\",\"data\":{\"code\":\"let cart = [];\\n\\ntry {\\n\\n    const savedCart = localStorage.getItem(\\\"shoppingCart\\\");\\n\\n    if (savedCart) {\\n\\n        const parsedCart = JSON.parse(savedCart);\\n\\n        if (Array.isArray(parsedCart)) {\\n            cart = parsedCart.filter(function(item) {\\n\\n                const validProduct = products.some(function(product) {\\n                    return product.id === item.id;\\n                });\\n\\n                return (\\n                    validProduct &amp;&amp;\\n                    Number.isInteger(item.quantity) &amp;&amp;\\n                    item.quantity &gt; 0\\n                );\\n\\n            });\\n        }\\n\\n    }\\n\\n} catch (error) {\\n\\n    console.error(\\\"Unable to load cart:\\\", error);\\n\\n    cart = [];\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"lDYGR17vkZ\",\"type\":\"header\",\"data\":{\"text\":\"Understanding This Code\",\"level\":3}},{\"id\":\"_aw8nUxdtz\",\"type\":\"paragraph\",\"data\":{\"text\":\"First:\"}},{\"id\":\"0d8Go-Abiw\",\"type\":\"code\",\"data\":{\"code\":\"let cart = [];\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"2vE16v_n4o\",\"type\":\"paragraph\",\"data\":{\"text\":\"We create an empty cart.\"}},{\"id\":\"ipMJA9Wbxr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Then:\"}},{\"id\":\"9SOlv7HGu0\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.getItem(\\\"shoppingCart\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"pc16KcqiI5\",\"type\":\"paragraph\",\"data\":{\"text\":\"We check whether a previously saved cart exists.\"}},{\"id\":\"H_pn3x2ac3\",\"type\":\"paragraph\",\"data\":{\"text\":\"If it exists, we convert the JSON string back into JavaScript data:\"}},{\"id\":\"XctlbLpOjk\",\"type\":\"code\",\"data\":{\"code\":\"JSON.parse(savedCart);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"ZNUyFTjncw\",\"type\":\"paragraph\",\"data\":{\"text\":\"We also check that the saved value is an array and contains valid product IDs and positive integer quantities.\"}},{\"id\":\"pQ176AlNqB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why do we use \"}},{\"id\":\"aHm7S6RygQ\",\"type\":\"code\",\"data\":{\"code\":\"try...catch\",\"language\":\"cpp\",\"raw\":true}},{\"id\":\"-OZ_TGRsWf\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because LocalStorage data can be invalid or corrupted. If JSON parsing fails, \"}},{\"id\":\"jNes7rki9P\",\"type\":\"code\",\"data\":{\"code\":\"catch\",\"language\":\"cpp\",\"raw\":true}},{\"id\":\"xdn3Kw6W6U\",\"type\":\"paragraph\",\"data\":{\"text\":\" prevents the entire JavaScript application from stopping.\"}},{\"id\":\"bXeoU7o06E\",\"type\":\"header\",\"data\":{\"text\":\"21. Create a Function to Save the Cart\",\"level\":2}},{\"id\":\"ItETP71Itt\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now create a reusable function:\"}},{\"id\":\"szDvVgNBv9\",\"type\":\"code\",\"data\":{\"code\":\"function saveCart() {\\n\\n    localStorage.setItem(\\n        \\\"shoppingCart\\\",\\n        JSON.stringify(cart)\\n    );\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"vN5XloqnaR\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Function\",\"level\":3}},{\"id\":\"BgN_PzxTm0\",\"type\":\"code\",\"data\":{\"code\":\"JSON.stringify(cart)\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"LYmpGd14Uj\",\"type\":\"paragraph\",\"data\":{\"text\":\"Converts the cart array into a string.\"}},{\"id\":\"5_rW02p_QU\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem(\\\"shoppingCart\\\", ...);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"eJQ-lQCaO1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Saves that string under the key \"}},{\"id\":\"D6iaDJ-l3G\",\"type\":\"code\",\"data\":{\"code\":\"shoppingCart\",\"language\":\"\",\"raw\":true}},{\"id\":\"Xuy6ayyVGV\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"oGGih6-Jei\",\"type\":\"paragraph\",\"data\":{\"text\":\"Whenever we add, remove, or update a product quantity, we will call this function.\"}},{\"id\":\"o7FapDLPqO\",\"type\":\"header\",\"data\":{\"text\":\"22. Implement Add to Cart\",\"level\":2}},{\"id\":\"8qBZb-WzO7\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's create the Add to Cart functionality.\"}},{\"id\":\"Ltd3DkSYIn\",\"type\":\"code\",\"data\":{\"code\":\"function addToCart(productId) {\\n\\n    const product = products.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!product || !product.inStock) {\\n        return;\\n    }\\n\\n    const existingItem = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (existingItem) {\\n\\n        existingItem.quantity++;\\n\\n    } else {\\n\\n        cart.push({\\n            id: productId,\\n            quantity: 1\\n        });\\n\\n    }\\n\\n    saveCart();\\n\\n    displayCart();\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"8jy8DV7vEB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Understanding \"}},{\"id\":\"N5wHAn2vAv\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"iI43adUHIE\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"CTNATEm4kd\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ZD-0GSGn7A\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns the first array element that satisfies a condition.\"}},{\"id\":\"MLUNiYI2p2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"OE0DhTlMOw\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nconst result = numbers.find(function(number) {\\n    return number &gt; 20;\\n});\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"5Ufg_S3gJr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"siun7OVNCx\",\"type\":\"code\",\"data\":{\"code\":\"30\",\"language\":\"\",\"raw\":true}},{\"id\":\"FSQkk8vHUj\",\"type\":\"paragraph\",\"data\":{\"text\":\"In our project:\"}},{\"id\":\"rlC-hoEMd7\",\"type\":\"code\",\"data\":{\"code\":\"const product = products.find(function(item) {\\n    return item.id === productId;\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"qed5z9TOQn\",\"type\":\"paragraph\",\"data\":{\"text\":\"We find the product whose ID matches the clicked product ID.\"}},{\"id\":\"pHHsGpLvDB\",\"type\":\"header\",\"data\":{\"text\":\"How Do We Prevent Duplicate Products?\",\"level\":3}},{\"id\":\"Ws-9LL3BHB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose a customer clicks Add to Cart twice for the same product.\"}},{\"id\":\"Fd0EZVSYz0\",\"type\":\"paragraph\",\"data\":{\"text\":\"We do not want two separate entries for that product.\"}},{\"id\":\"fGMeDVu7Nh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead, we want:\"}},{\"id\":\"iy6I9JU0VP\",\"type\":\"code\",\"data\":{\"code\":\"[\\n    {\\n        id: 1,\\n        quantity: 2\\n    }\\n]\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"uRg8z3XjeE\",\"type\":\"paragraph\",\"data\":{\"text\":\"That's why we check:\"}},{\"id\":\"JoMV7IsPSs\",\"type\":\"code\",\"data\":{\"code\":\"const existingItem = cart.find(function(item) {\\n    return item.id === productId;\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Q00g8-ovh4\",\"type\":\"paragraph\",\"data\":{\"text\":\"If the product already exists:\"}},{\"id\":\"ZjybX3gFfh\",\"type\":\"code\",\"data\":{\"code\":\"existingItem.quantity++;\",\"language\":\"\",\"raw\":true}},{\"id\":\"D6Np_d2keG\",\"type\":\"paragraph\",\"data\":{\"text\":\"We increase its quantity.\"}},{\"id\":\"URu8Kwf0ry\",\"type\":\"paragraph\",\"data\":{\"text\":\"Otherwise:\"}},{\"id\":\"yCY2tNkkj_\",\"type\":\"code\",\"data\":{\"code\":\"cart.push({\\n    id: productId,\\n    quantity: 1\\n});\",\"language\":\"php\",\"raw\":true}},{\"id\":\"63-xxhDbbw\",\"type\":\"paragraph\",\"data\":{\"text\":\"We add a new cart item.\"}},{\"id\":\"Jf-uCHk8IY\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is how we prevent duplicate cart entries.\"}},{\"id\":\"TPSOQij9EW\",\"type\":\"header\",\"data\":{\"text\":\"23. Connect Product Buttons Using Event Delegation\",\"level\":2}},{\"id\":\"QRT8wf9wWm\",\"type\":\"paragraph\",\"data\":{\"text\":\"We need to detect which product's Add to Cart button was clicked.\"}},{\"id\":\"QFtz6_iEED\",\"type\":\"paragraph\",\"data\":{\"text\":\"We can use event delegation.\"}},{\"id\":\"8kU3pc98FU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"7MnitnwvD4\",\"type\":\"code\",\"data\":{\"code\":\"productList.addEventListener(\\\"click\\\", function(event) {\\n\\n    if (event.target.matches(\\\"button[data-id]\\\")) {\\n\\n        const productId = Number(event.target.dataset.id);\\n\\n        addToCart(productId);\\n\\n    }\\n\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"30my7GcLZ4\",\"type\":\"header\",\"data\":{\"text\":\"What Is Event Delegation?\",\"level\":3}},{\"id\":\"2A9ifTwl8s\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead of adding a separate click event listener to every product button, we add one listener to their parent container.\"}},{\"id\":\"l2aYv7QWde\",\"type\":\"paragraph\",\"data\":{\"text\":\"When a button is clicked, the click event bubbles up to \"}},{\"id\":\"-fm4zohlhK\",\"type\":\"code\",\"data\":{\"code\":\"productList\",\"language\":\"\",\"raw\":true}},{\"id\":\"HK-nSRT1cT\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"mOEsREUF7R\",\"type\":\"paragraph\",\"data\":{\"text\":\"Then we check:\"}},{\"id\":\"yC8xj825BV\",\"type\":\"code\",\"data\":{\"code\":\"event.target.matches(\\\"button[data-id]\\\")\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"Mbhq7C34vE\",\"type\":\"paragraph\",\"data\":{\"text\":\"This confirms that the clicked element is a product button.\"}},{\"id\":\"cOZEOkBAL6\",\"type\":\"paragraph\",\"data\":{\"text\":\"We retrieve its product ID using:\"}},{\"id\":\"ZbDhLRmMqy\",\"type\":\"code\",\"data\":{\"code\":\"event.target.dataset.id\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"d9ZDAr-Gqx\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"9Jfz2S3omB\",\"type\":\"code\",\"data\":{\"code\":\"dataset\",\"language\":\"\",\"raw\":true}},{\"id\":\"nknftmdqZc\",\"type\":\"paragraph\",\"data\":{\"text\":\" property allows JavaScript to read custom \"}},{\"id\":\"sKUtH7sAEo\",\"type\":\"code\",\"data\":{\"code\":\"data-*\",\"language\":\"kotlin\",\"raw\":true}},{\"id\":\"vz4smVmfE1\",\"type\":\"paragraph\",\"data\":{\"text\":\" HTML attributes.\"}},{\"id\":\"jl46h29QFV\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"cgNBnnWSVl\",\"type\":\"code\",\"data\":{\"code\":\"Add to Cart\",\"language\":\"html\",\"raw\":true}},{\"id\":\"BHFXioSurY\",\"type\":\"paragraph\",\"data\":{\"text\":\"We convert the ID into a number because our product IDs are numbers.\"}},{\"id\":\"mvW-pcSsTF\",\"type\":\"header\",\"data\":{\"text\":\"24. Display Shopping Cart Items\",\"level\":2}},{\"id\":\"JZHjkZ63eA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now we need to show the products inside the cart.\"}},{\"id\":\"Z88hwTdq92\",\"type\":\"paragraph\",\"data\":{\"text\":\"Create:\"}},{\"id\":\"e3u01M4EiQ\",\"type\":\"code\",\"data\":{\"code\":\"function displayCart() {\\n\\n    cartItems.innerHTML = \\\"\\\";\\n\\n    let totalItems = 0;\\n\\n    if (cart.length === 0) {\\n\\n        cartItems.innerHTML =\\n            'Your cart is empty.';\\n\\n        cartCount.textContent = \\\"0\\\";\\n\\n        cartTotal.textContent = \\\"\u20b90\\\";\\n\\n        return;\\n    }\\n\\n    let totalPrice = 0;\\n\\n    cart.forEach(function(item) {\\n\\n        const product = products.find(function(product) {\\n            return product.id === item.id;\\n        });\\n\\n        if (!product) {\\n            return;\\n        }\\n\\n        const itemTotal = product.price * item.quantity;\\n\\n        totalPrice += itemTotal;\\n\\n        totalItems += item.quantity;\\n\\n        const cartItem = document.createElement(\\\"div\\\");\\n\\n        cartItem.className = \\\"cart-item\\\";\\n\\n        const details = document.createElement(\\\"div\\\");\\n\\n        const name = document.createElement(\\\"h3\\\");\\n        name.textContent = product.name;\\n\\n        const price = document.createElement(\\\"p\\\");\\n        price.textContent = `\u20b9${product.price} \u00d7 ${item.quantity}`;\\n\\n        details.append(name, price);\\n\\n        const actions = document.createElement(\\\"div\\\");\\n\\n        actions.className = \\\"cart-actions\\\";\\n\\n        const decreaseButton = document.createElement(\\\"button\\\");\\n        decreaseButton.textContent = \\\"-\\\";\\n        decreaseButton.dataset.action = \\\"decrease\\\";\\n        decreaseButton.dataset.id = item.id;\\n\\n        const quantity = document.createElement(\\\"span\\\");\\n        quantity.textContent = item.quantity;\\n\\n        const increaseButton = document.createElement(\\\"button\\\");\\n        increaseButton.textContent = \\\"+\\\";\\n        increaseButton.dataset.action = \\\"increase\\\";\\n        increaseButton.dataset.id = item.id;\\n\\n        const removeButton = document.createElement(\\\"button\\\");\\n        removeButton.textContent = \\\"Remove\\\";\\n        removeButton.className = \\\"remove-button\\\";\\n        removeButton.dataset.action = \\\"remove\\\";\\n        removeButton.dataset.id = item.id;\\n\\n        actions.append(\\n            decreaseButton,\\n            quantity,\\n            increaseButton,\\n            removeButton\\n        );\\n\\n        cartItem.append(details, actions);\\n\\n        cartItems.appendChild(cartItem);\\n\\n    });\\n\\n    cartCount.textContent = totalItems;\\n\\n    cartTotal.textContent =\\n        `\u20b9${totalPrice.toLocaleString(\\\"en-IN\\\")}`;\\n\\n}\",\"language\":\"html\",\"raw\":true}},{\"id\":\"njDiRHsfK6\",\"type\":\"header\",\"data\":{\"text\":\"Understanding Cart Total\",\"level\":3}},{\"id\":\"s-OMTHPcov\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose a customer adds:\"}},{\"id\":\"QHYR8YYpiK\",\"type\":\"paragraph\",\"data\":{\"text\":\"ProductPriceQuantityTotalHeadphones\u20b91,4992\u20b92,998Running Shoes\u20b91,9991\u20b91,999\"}},{\"id\":\"zC0tbsC1eI\",\"type\":\"paragraph\",\"data\":{\"text\":\"The total is:\"}},{\"id\":\"WhBGPbWCrm\",\"type\":\"code\",\"data\":{\"code\":\"2998 + 1999 = 4997\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"LCgMvdkPdc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Our code calculates the total using:\"}},{\"id\":\"o8sKPfAzRc\",\"type\":\"code\",\"data\":{\"code\":\"const itemTotal = product.price * item.quantity;\\n\\ntotalPrice += itemTotal;\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"fwZ_oJ3ASl\",\"type\":\"paragraph\",\"data\":{\"text\":\"For each cart item, we multiply its price by its quantity and add the result to \"}},{\"id\":\"Orbar9CndZ\",\"type\":\"code\",\"data\":{\"code\":\"totalPrice\",\"language\":\"\",\"raw\":true}},{\"id\":\"be_R4Lk86C\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"YWM0kvPYWV\",\"type\":\"paragraph\",\"data\":{\"text\":\"We also calculate the total number of items:\"}},{\"id\":\"0J--eqN5RA\",\"type\":\"code\",\"data\":{\"code\":\"totalItems += item.quantity;\",\"language\":\"makefile\",\"raw\":true}},{\"id\":\"_8B1iydtV2\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is why the cart indicator displays the total quantity rather than the number of different product types.\"}},{\"id\":\"pfUUwAmJn-\",\"type\":\"header\",\"data\":{\"text\":\"25. Increase and Decrease Product Quantity\",\"level\":2}},{\"id\":\"fKWRqr02FN\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's implement the plus and minus buttons.\"}},{\"id\":\"KJtXTpnM92\",\"type\":\"code\",\"data\":{\"code\":\"function increaseQuantity(productId) {\\n\\n    const item = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!item) {\\n        return;\\n    }\\n\\n    item.quantity++;\\n\\n    saveCart();\\n\\n    displayCart();\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"y3SAbPz73_\",\"type\":\"paragraph\",\"data\":{\"text\":\"When the customer clicks the plus button, we find the matching cart item and increase its quantity.\"}},{\"id\":\"QvJM7va9p4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now the decrease function:\"}},{\"id\":\"D3zJLJyBId\",\"type\":\"code\",\"data\":{\"code\":\"function decreaseQuantity(productId) {\\n\\n    const item = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!item) {\\n        return;\\n    }\\n\\n    item.quantity--;\\n\\n    if (item.quantity &lt;= 0) {\\n\\n        removeFromCart(productId);\\n\\n        return;\\n    }\\n\\n    saveCart();\\n\\n    displayCart();\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"K9mpQm5axj\",\"type\":\"paragraph\",\"data\":{\"text\":\"If the quantity becomes zero, we remove the product from the cart.\"}},{\"id\":\"3qNQr1G6YU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why?\"}},{\"id\":\"KxyNoU3ktV\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because a shopping cart should not contain products with zero quantity.\"}},{\"id\":\"kysYp4-H5G\",\"type\":\"header\",\"data\":{\"text\":\"26. Remove Product from Cart\",\"level\":2}},{\"id\":\"sbZhDJ4KNJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Create:\"}},{\"id\":\"pOgxtF3oKs\",\"type\":\"code\",\"data\":{\"code\":\"function removeFromCart(productId) {\\n\\n    cart = cart.filter(function(item) {\\n\\n        return item.id !== productId;\\n\\n    });\\n\\n    saveCart();\\n\\n    displayCart();\\n\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"m8YV_xtyVc\",\"type\":\"header\",\"data\":{\"text\":\"Understanding the Logic\",\"level\":3}},{\"id\":\"ToWaYI4Eyh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose our cart contains:\"}},{\"id\":\"wc5D8DFulb\",\"type\":\"code\",\"data\":{\"code\":\"[\\n    { id: 1, quantity: 2 },\\n    { id: 3, quantity: 1 },\\n    { id: 5, quantity: 1 }\\n]\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"FxmzDnzqDE\",\"type\":\"paragraph\",\"data\":{\"text\":\"We want to remove product ID 3.\"}},{\"id\":\"wPQmk9Wept\",\"type\":\"paragraph\",\"data\":{\"text\":\"Our condition is:\"}},{\"id\":\"38lenO398V\",\"type\":\"code\",\"data\":{\"code\":\"item.id !== productId\",\"language\":\"python\",\"raw\":true}},{\"id\":\"1EYEyo0AnH\",\"type\":\"paragraph\",\"data\":{\"text\":\"This means we keep all items except the product whose ID matches the selected product ID.\"}},{\"id\":\"Q98GvqVMcN\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"L7GpytzdYK\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"m20F-9StVE\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a new array without that item.\"}},{\"id\":\"W-riyOSDCz\",\"type\":\"header\",\"data\":{\"text\":\"27. Handle Cart Button Clicks\",\"level\":2}},{\"id\":\"t4L0YGZo--\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now we need to connect the cart buttons with their functions.\"}},{\"id\":\"YZQDwsxVlC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"SnjVJQImU2\",\"type\":\"code\",\"data\":{\"code\":\"cartItems.addEventListener(\\\"click\\\", function(event) {\\n\\n    const button = event.target.closest(\\\"button[data-action]\\\");\\n\\n    if (!button) {\\n        return;\\n    }\\n\\n    const productId = Number(button.dataset.id);\\n\\n    const action = button.dataset.action;\\n\\n    if (action === \\\"increase\\\") {\\n\\n        increaseQuantity(productId);\\n\\n    } else if (action === \\\"decrease\\\") {\\n\\n        decreaseQuantity(productId);\\n\\n    } else if (action === \\\"remove\\\") {\\n\\n        removeFromCart(productId);\\n\\n    }\\n\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"YEtpshBKRg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why Do We Use \"}},{\"id\":\"eCaMSk9dAi\",\"type\":\"code\",\"data\":{\"code\":\"closest()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"dldkH9C94V\",\"type\":\"paragraph\",\"data\":{\"text\":\"?\"}},{\"id\":\"KEUD6oozRr\",\"type\":\"code\",\"data\":{\"code\":\"event.target.closest(\\\"button[data-action]\\\")\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"OR8sMYK3CK\",\"type\":\"paragraph\",\"data\":{\"text\":\"It finds the closest matching button starting from the clicked element.\"}},{\"id\":\"Zs9Q1PngyR\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is useful when the button contains nested elements.\"}},{\"id\":\"A2-9JitYB7\",\"type\":\"paragraph\",\"data\":{\"text\":\"We then read:\"}},{\"id\":\"3JoB3cHbez\",\"type\":\"code\",\"data\":{\"code\":\"button.dataset.action\",\"language\":\"css\",\"raw\":true}},{\"id\":\"yttXfk84rY\",\"type\":\"paragraph\",\"data\":{\"text\":\"It tells us whether the customer clicked:\"}},{\"id\":\"aeUxIVb3_c\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Increase\",\"Decrease\",\"Remove\"]}},{\"id\":\"zW2tD_tcAS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Based on that value, we call the correct function.\"}},{\"id\":\"z8zfBdbgt4\",\"type\":\"header\",\"data\":{\"text\":\"28. Implement Clear Cart\",\"level\":2}},{\"id\":\"lRyxUH_grd\",\"type\":\"paragraph\",\"data\":{\"text\":\"Sometimes a customer wants to remove everything from the cart.\"}},{\"id\":\"4XiKZWB3MJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add:\"}},{\"id\":\"M_0toH8zPB\",\"type\":\"code\",\"data\":{\"code\":\"clearCartButton.addEventListener(\\\"click\\\", function() {\\n\\n    cart = [];\\n\\n    saveCart();\\n\\n    displayCart();\\n\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"3DOw7_B9Xd\",\"type\":\"header\",\"data\":{\"text\":\"How Does It Work?\",\"level\":3}},{\"id\":\"K6UjbNeQzy\",\"type\":\"code\",\"data\":{\"code\":\"cart = [];\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"vv0QALMfmZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Replaces the existing cart with an empty array.\"}},{\"id\":\"FuYYUNMJTq\",\"type\":\"code\",\"data\":{\"code\":\"saveCart();\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"CF0lQo6SmV\",\"type\":\"paragraph\",\"data\":{\"text\":\"Updates LocalStorage.\"}},{\"id\":\"PkpjrA0-er\",\"type\":\"code\",\"data\":{\"code\":\"displayCart();\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"bTKST0Kp25\",\"type\":\"paragraph\",\"data\":{\"text\":\"Refreshes the cart display.\"}},{\"id\":\"p_HIZfjcir\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now the cart will show the empty-cart message.\"}},{\"id\":\"ZO_wgOd8Bi\",\"type\":\"header\",\"data\":{\"text\":\"29. Initialize the Product Page\",\"level\":2}},{\"id\":\"2ZgFZpI5Wk\",\"type\":\"paragraph\",\"data\":{\"text\":\"We have created all the main functions.\"}},{\"id\":\"ddiSw0ciUA\",\"type\":\"paragraph\",\"data\":{\"text\":\"But we still need to display products and restore the cart when the page first opens.\"}},{\"id\":\"mdlOgpKsHw\",\"type\":\"paragraph\",\"data\":{\"text\":\"Add this at the bottom of \"}},{\"id\":\"5zi97MmaRT\",\"type\":\"code\",\"data\":{\"code\":\"script.js\",\"language\":\"\",\"raw\":true}},{\"id\":\"3GwW2f8R6g\",\"type\":\"paragraph\",\"data\":{\"text\":\":\"}},{\"id\":\"FU66Fxhqw1\",\"type\":\"code\",\"data\":{\"code\":\"updateProductPage();\\n\\ndisplayCart();\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"RN3JF00Bgk\",\"type\":\"paragraph\",\"data\":{\"text\":\"The first function displays the products using the current filter values.\"}},{\"id\":\"EDbNi5_vhY\",\"type\":\"paragraph\",\"data\":{\"text\":\"The second function displays any cart data loaded from LocalStorage.\"}},{\"id\":\"eQfrjDX6Tm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Without these calls, the functions would exist, but the page would not automatically render the products and cart on initial load.\"}},{\"id\":\"NXUQn8JQG7\",\"type\":\"header\",\"data\":{\"text\":\"30. Complete JavaScript Code\",\"level\":2}},{\"id\":\"fFDiCMLHbh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is the complete \"}},{\"id\":\"2xdi4zHYq_\",\"type\":\"code\",\"data\":{\"code\":\"script.js\",\"language\":\"\",\"raw\":true}},{\"id\":\"zfoYsrpDKH\",\"type\":\"paragraph\",\"data\":{\"text\":\" file in one place.\"}},{\"id\":\"YlZJV51DTq\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you followed the steps above, you have already written each part. This combined version is useful when you want to check your code or build the project from scratch.\"}},{\"id\":\"oF45enWhW2\",\"type\":\"code\",\"data\":{\"code\":\"\/\/ ===================================\\n\/\/ 1. PRODUCT DATA\\n\/\/ ===================================\\n\\nconst products = [\\n    { id: 1, name: \\\"Wireless Headphones\\\", price: 1499, category: \\\"Electronics\\\", rating: 4.5, inStock: true, image: \\\"\ud83c\udfa7\\\" },\\n    { id: 2, name: \\\"Smart Watch\\\", price: 2499, category: \\\"Electronics\\\", rating: 4.2, inStock: true, image: \\\"\u231a\\\" },\\n    { id: 3, name: \\\"Running Shoes\\\", price: 1999, category: \\\"Fashion\\\", rating: 4.7, inStock: true, image: \\\"\ud83d\udc5f\\\" },\\n    { id: 4, name: \\\"Casual T-Shirt\\\", price: 599, category: \\\"Fashion\\\", rating: 4.0, inStock: false, image: \\\"\ud83d\udc55\\\" },\\n    { id: 5, name: \\\"Laptop\\\", price: 45999, category: \\\"Electronics\\\", rating: 4.8, inStock: true, image: \\\"\ud83d\udcbb\\\" },\\n    { id: 6, name: \\\"Backpack\\\", price: 1299, category: \\\"Accessories\\\", rating: 4.1, inStock: true, image: \\\"\ud83c\udf92\\\" },\\n    { id: 7, name: \\\"Sunglasses\\\", price: 899, category: \\\"Accessories\\\", rating: 3.9, inStock: true, image: \\\"\ud83d\udd76\ufe0f\\\" },\\n    { id: 8, name: \\\"Bluetooth Speaker\\\", price: 1799, category: \\\"Electronics\\\", rating: 4.3, inStock: false, image: \\\"\ud83d\udd0a\\\" },\\n    { id: 9, name: \\\"Denim Jacket\\\", price: 2299, category: \\\"Fashion\\\", rating: 4.6, inStock: true, image: \\\"\ud83e\udde5\\\" },\\n    { id: 10, name: \\\"Leather Wallet\\\", price: 799, category: \\\"Accessories\\\", rating: 4.4, inStock: true, image: \\\"\ud83d\udc5b\\\" },\\n    { id: 11, name: \\\"Gaming Mouse\\\", price: 999, category: \\\"Electronics\\\", rating: 4.5, inStock: true, image: \\\"\ud83d\uddb1\ufe0f\\\" },\\n    { id: 12, name: \\\"Sports Cap\\\", price: 499, category: \\\"Fashion\\\", rating: 3.8, inStock: true, image: \\\"\ud83e\udde2\\\" }\\n];\\n\\n\/\/ ===================================\\n\/\/ 2. SELECT HTML ELEMENTS\\n\/\/ ===================================\\n\\nconst productList = document.getElementById(\\\"product-list\\\");\\nconst searchInput = document.getElementById(\\\"search-input\\\");\\nconst categoryFilter = document.getElementById(\\\"category-filter\\\");\\nconst minPriceInput = document.getElementById(\\\"min-price\\\");\\nconst maxPriceInput = document.getElementById(\\\"max-price\\\");\\nconst ratingFilter = document.getElementById(\\\"rating-filter\\\");\\nconst stockFilter = document.getElementById(\\\"stock-filter\\\");\\nconst sortFilter = document.getElementById(\\\"sort-filter\\\");\\nconst productCount = document.getElementById(\\\"product-count\\\");\\n\\nconst cartItems = document.getElementById(\\\"cart-items\\\");\\nconst cartCount = document.getElementById(\\\"cart-count\\\");\\nconst cartTotal = document.getElementById(\\\"cart-total\\\");\\n\\nconst resetFiltersButton = document.getElementById(\\\"reset-filters\\\");\\nconst clearCartButton = document.getElementById(\\\"clear-cart\\\");\\n\\n\/\/ ===================================\\n\/\/ 3. LOAD CART FROM LOCALSTORAGE\\n\/\/ ===================================\\n\\nlet cart = [];\\n\\ntry {\\n\\n    const savedCart = localStorage.getItem(\\\"shoppingCart\\\");\\n\\n    if (savedCart) {\\n\\n        const parsedCart = JSON.parse(savedCart);\\n\\n        if (Array.isArray(parsedCart)) {\\n\\n            cart = parsedCart.filter(function(item) {\\n\\n                const validProduct = products.some(function(product) {\\n                    return product.id === item.id;\\n                });\\n\\n                return (\\n                    validProduct &amp;&amp;\\n                    Number.isInteger(item.quantity) &amp;&amp;\\n                    item.quantity &gt; 0\\n                );\\n\\n            });\\n\\n        }\\n\\n    }\\n\\n} catch (error) {\\n\\n    console.error(\\\"Unable to load cart:\\\", error);\\n\\n    cart = [];\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 4. DISPLAY PRODUCTS\\n\/\/ ===================================\\n\\nfunction displayProducts(productArray) {\\n\\n    productList.innerHTML = \\\"\\\";\\n\\n    if (productArray.length === 0) {\\n\\n        productList.innerHTML =\\n            'No products found.';\\n\\n        productCount.textContent = \\\"0 products found\\\";\\n\\n        return;\\n    }\\n\\n    productArray.forEach(function(product) {\\n\\n        const card = document.createElement(\\\"div\\\");\\n        card.className = \\\"product-card\\\";\\n\\n        const image = document.createElement(\\\"div\\\");\\n        image.className = \\\"product-image\\\";\\n        image.textContent = product.image;\\n\\n        const name = document.createElement(\\\"h3\\\");\\n        name.textContent = product.name;\\n\\n        const price = document.createElement(\\\"p\\\");\\n        price.textContent = `Price: \u20b9${product.price}`;\\n\\n        const category = document.createElement(\\\"p\\\");\\n        category.textContent = `Category: ${product.category}`;\\n\\n        const rating = document.createElement(\\\"p\\\");\\n        rating.textContent = `Rating: \u2b50 ${product.rating}`;\\n\\n        const stock = document.createElement(\\\"p\\\");\\n        stock.textContent = product.inStock\\n            ? \\\"In Stock\\\"\\n            : \\\"Out of Stock\\\";\\n\\n        const button = document.createElement(\\\"button\\\");\\n\\n        button.textContent = product.inStock\\n            ? \\\"Add to Cart\\\"\\n            : \\\"Out of Stock\\\";\\n\\n        button.dataset.id = product.id;\\n        button.disabled = !product.inStock;\\n\\n        card.append(\\n            image,\\n            name,\\n            price,\\n            category,\\n            rating,\\n            stock,\\n            button\\n        );\\n\\n        productList.appendChild(card);\\n\\n    });\\n\\n    productCount.textContent =\\n        `${productArray.length} products found`;\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 5. SEARCH PRODUCTS\\n\/\/ ===================================\\n\\nfunction searchProducts(productArray) {\\n\\n    const searchTerm = searchInput.value.toLowerCase().trim();\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.name\\n            .toLowerCase()\\n            .includes(searchTerm);\\n\\n    });\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 6. CATEGORY FILTER\\n\/\/ ===================================\\n\\nfunction filterByCategory(productArray) {\\n\\n    const selectedCategory = categoryFilter.value;\\n\\n    return productArray.filter(function(product) {\\n\\n        if (selectedCategory === \\\"all\\\") {\\n            return true;\\n        }\\n\\n        return product.category === selectedCategory;\\n\\n    });\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 7. PRICE FILTER\\n\/\/ ===================================\\n\\nfunction filterByPrice(productArray) {\\n\\n    const minPrice = minPriceInput.value;\\n    const maxPrice = maxPriceInput.value;\\n\\n    return productArray.filter(function(product) {\\n\\n        const matchesMinPrice =\\n            minPrice === \\\"\\\" ||\\n            product.price &gt;= Number(minPrice);\\n\\n        const matchesMaxPrice =\\n            maxPrice === \\\"\\\" ||\\n            product.price &lt;= Number(maxPrice);\\n\\n        return matchesMinPrice &amp;&amp; matchesMaxPrice;\\n\\n    });\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 8. RATING FILTER\\n\/\/ ===================================\\n\\nfunction filterByRating(productArray) {\\n\\n    const minimumRating = Number(ratingFilter.value);\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.rating &gt;= minimumRating;\\n\\n    });\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 9. STOCK FILTER\\n\/\/ ===================================\\n\\nfunction filterByStock(productArray) {\\n\\n    const onlyInStock = stockFilter.checked;\\n\\n    if (!onlyInStock) {\\n        return productArray;\\n    }\\n\\n    return productArray.filter(function(product) {\\n\\n        return product.inStock === true;\\n\\n    });\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 10. SORT PRODUCTS\\n\/\/ ===================================\\n\\nfunction sortProducts(productArray) {\\n\\n    const sortValue = sortFilter.value;\\n\\n    const sortedProducts = [...productArray];\\n\\n    if (sortValue === \\\"price-low\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return a.price - b.price;\\n        });\\n\\n    } else if (sortValue === \\\"price-high\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return b.price - a.price;\\n        });\\n\\n    } else if (sortValue === \\\"rating-high\\\") {\\n\\n        sortedProducts.sort(function(a, b) {\\n            return b.rating - a.rating;\\n        });\\n\\n    }\\n\\n    return sortedProducts;\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 11. UPDATE PRODUCT PAGE\\n\/\/ ===================================\\n\\nfunction updateProductPage() {\\n\\n    let filteredProducts = products;\\n\\n    filteredProducts = searchProducts(filteredProducts);\\n    filteredProducts = filterByCategory(filteredProducts);\\n    filteredProducts = filterByPrice(filteredProducts);\\n    filteredProducts = filterByRating(filteredProducts);\\n    filteredProducts = filterByStock(filteredProducts);\\n\\n    const sortedProducts = sortProducts(filteredProducts);\\n\\n    displayProducts(sortedProducts);\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 12. RESET FILTERS\\n\/\/ ===================================\\n\\nresetFiltersButton.addEventListener(\\\"click\\\", function() {\\n\\n    searchInput.value = \\\"\\\";\\n    categoryFilter.value = \\\"all\\\";\\n    minPriceInput.value = \\\"\\\";\\n    maxPriceInput.value = \\\"\\\";\\n    ratingFilter.value = \\\"0\\\";\\n    stockFilter.checked = false;\\n    sortFilter.value = \\\"default\\\";\\n\\n    updateProductPage();\\n\\n});\\n\\n\/\/ ===================================\\n\/\/ 13. FILTER EVENT LISTENERS\\n\/\/ ===================================\\n\\nsearchInput.addEventListener(\\\"input\\\", updateProductPage);\\ncategoryFilter.addEventListener(\\\"change\\\", updateProductPage);\\nminPriceInput.addEventListener(\\\"input\\\", updateProductPage);\\nmaxPriceInput.addEventListener(\\\"input\\\", updateProductPage);\\nratingFilter.addEventListener(\\\"change\\\", updateProductPage);\\nstockFilter.addEventListener(\\\"change\\\", updateProductPage);\\nsortFilter.addEventListener(\\\"change\\\", updateProductPage);\\n\\n\/\/ ===================================\\n\/\/ 14. SAVE CART\\n\/\/ ===================================\\n\\nfunction saveCart() {\\n\\n    localStorage.setItem(\\n        \\\"shoppingCart\\\",\\n        JSON.stringify(cart)\\n    );\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 15. ADD TO CART\\n\/\/ ===================================\\n\\nfunction addToCart(productId) {\\n\\n    const product = products.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!product || !product.inStock) {\\n        return;\\n    }\\n\\n    const existingItem = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (existingItem) {\\n\\n        existingItem.quantity++;\\n\\n    } else {\\n\\n        cart.push({\\n            id: productId,\\n            quantity: 1\\n        });\\n\\n    }\\n\\n    saveCart();\\n    displayCart();\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 16. PRODUCT BUTTON EVENT\\n\/\/ ===================================\\n\\nproductList.addEventListener(\\\"click\\\", function(event) {\\n\\n    if (event.target.matches(\\\"button[data-id]\\\")) {\\n\\n        const productId = Number(event.target.dataset.id);\\n\\n        addToCart(productId);\\n\\n    }\\n\\n});\\n\\n\/\/ ===================================\\n\/\/ 17. DISPLAY CART\\n\/\/ ===================================\\n\\nfunction displayCart() {\\n\\n    cartItems.innerHTML = \\\"\\\";\\n\\n    let totalItems = 0;\\n    let totalPrice = 0;\\n\\n    if (cart.length === 0) {\\n\\n        cartItems.innerHTML =\\n            'Your cart is empty.';\\n\\n        cartCount.textContent = \\\"0\\\";\\n        cartTotal.textContent = \\\"\u20b90\\\";\\n\\n        return;\\n    }\\n\\n    cart.forEach(function(item) {\\n\\n        const product = products.find(function(product) {\\n            return product.id === item.id;\\n        });\\n\\n        if (!product) {\\n            return;\\n        }\\n\\n        const itemTotal = product.price * item.quantity;\\n\\n        totalPrice += itemTotal;\\n        totalItems += item.quantity;\\n\\n        const cartItem = document.createElement(\\\"div\\\");\\n        cartItem.className = \\\"cart-item\\\";\\n\\n        const details = document.createElement(\\\"div\\\");\\n\\n        const name = document.createElement(\\\"h3\\\");\\n        name.textContent = product.name;\\n\\n        const price = document.createElement(\\\"p\\\");\\n        price.textContent = `\u20b9${product.price} \u00d7 ${item.quantity}`;\\n\\n        details.append(name, price);\\n\\n        const actions = document.createElement(\\\"div\\\");\\n        actions.className = \\\"cart-actions\\\";\\n\\n        const decreaseButton = document.createElement(\\\"button\\\");\\n        decreaseButton.textContent = \\\"-\\\";\\n        decreaseButton.dataset.action = \\\"decrease\\\";\\n        decreaseButton.dataset.id = item.id;\\n\\n        const quantity = document.createElement(\\\"span\\\");\\n        quantity.textContent = item.quantity;\\n\\n        const increaseButton = document.createElement(\\\"button\\\");\\n        increaseButton.textContent = \\\"+\\\";\\n        increaseButton.dataset.action = \\\"increase\\\";\\n        increaseButton.dataset.id = item.id;\\n\\n        const removeButton = document.createElement(\\\"button\\\");\\n        removeButton.textContent = \\\"Remove\\\";\\n        removeButton.className = \\\"remove-button\\\";\\n        removeButton.dataset.action = \\\"remove\\\";\\n        removeButton.dataset.id = item.id;\\n\\n        actions.append(\\n            decreaseButton,\\n            quantity,\\n            increaseButton,\\n            removeButton\\n        );\\n\\n        cartItem.append(details, actions);\\n\\n        cartItems.appendChild(cartItem);\\n\\n    });\\n\\n    cartCount.textContent = totalItems;\\n\\n    cartTotal.textContent =\\n        `\u20b9${totalPrice.toLocaleString(\\\"en-IN\\\")}`;\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 18. QUANTITY FUNCTIONS\\n\/\/ ===================================\\n\\nfunction increaseQuantity(productId) {\\n\\n    const item = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!item) {\\n        return;\\n    }\\n\\n    item.quantity++;\\n\\n    saveCart();\\n    displayCart();\\n\\n}\\n\\nfunction decreaseQuantity(productId) {\\n\\n    const item = cart.find(function(item) {\\n        return item.id === productId;\\n    });\\n\\n    if (!item) {\\n        return;\\n    }\\n\\n    item.quantity--;\\n\\n    if (item.quantity &lt;= 0) {\\n\\n        removeFromCart(productId);\\n\\n        return;\\n    }\\n\\n    saveCart();\\n    displayCart();\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 19. REMOVE FROM CART\\n\/\/ ===================================\\n\\nfunction removeFromCart(productId) {\\n\\n    cart = cart.filter(function(item) {\\n\\n        return item.id !== productId;\\n\\n    });\\n\\n    saveCart();\\n    displayCart();\\n\\n}\\n\\n\/\/ ===================================\\n\/\/ 20. CART BUTTON EVENTS\\n\/\/ ===================================\\n\\ncartItems.addEventListener(\\\"click\\\", function(event) {\\n\\n    const button = event.target.closest(\\\"button[data-action]\\\");\\n\\n    if (!button) {\\n        return;\\n    }\\n\\n    const productId = Number(button.dataset.id);\\n\\n    const action = button.dataset.action;\\n\\n    if (action === \\\"increase\\\") {\\n\\n        increaseQuantity(productId);\\n\\n    } else if (action === \\\"decrease\\\") {\\n\\n        decreaseQuantity(productId);\\n\\n    } else if (action === \\\"remove\\\") {\\n\\n        removeFromCart(productId);\\n\\n    }\\n\\n});\\n\\n\/\/ ===================================\\n\/\/ 21. CLEAR CART\\n\/\/ ===================================\\n\\nclearCartButton.addEventListener(\\\"click\\\", function() {\\n\\n    cart = [];\\n\\n    saveCart();\\n    displayCart();\\n\\n});\\n\\n\/\/ ===================================\\n\/\/ 22. INITIAL PAGE LOAD\\n\/\/ ===================================\\n\\nupdateProductPage();\\n\\ndisplayCart();\",\"language\":\"html\",\"raw\":true}},{\"id\":\"mbDDEd8qok\",\"type\":\"header\",\"data\":{\"text\":\"31. How to Test the Project\",\"level\":2}},{\"id\":\"zqKoXLH_Ae\",\"type\":\"paragraph\",\"data\":{\"text\":\"After writing all three files, open \"}},{\"id\":\"ds4NDJSAnn\",\"type\":\"code\",\"data\":{\"code\":\"index.html\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"-tlYZAQsZ8\",\"type\":\"paragraph\",\"data\":{\"text\":\" in your browser.\"}},{\"id\":\"9Qttvxaaz5\",\"type\":\"paragraph\",\"data\":{\"text\":\"Follow these steps to test the functionality.\"}},{\"id\":\"u4rinE9ybe\",\"type\":\"paragraph\",\"data\":{\"text\":\"TestExpected resultOpen the pageAll 12 products appearSearch for LaptopOnly Laptop appearsSelect ElectronicsOnly electronics appearSet minimum price to 1,000Cheaper products disappearSet maximum price to 2,000More expensive products disappearSelect 4+ StarsProducts below 4 stars disappearEnable In-stock onlyOut-of-stock products disappearSelect Price: Low to HighCheapest products appear firstClick Add to Cart twiceOne cart entry with quantity 2Click +Quantity increasesClick -Quantity decreasesClick RemoveProduct disappears from cartRefresh the pageCart data remainsClick Clear CartCart becomes emptyClick Reset FiltersAll products appear again\"}},{\"id\":\"L7qZrNbZgp\",\"type\":\"header\",\"data\":{\"text\":\"32. Important Things to Understand About LocalStorage\",\"level\":2}},{\"id\":\"HNnYC-U1SI\",\"type\":\"paragraph\",\"data\":{\"text\":\"LocalStorage is useful for learning and building small frontend projects, but it has limitations.\"}},{\"id\":\"VkA2LQrnZO\",\"type\":\"paragraph\",\"data\":{\"text\":\"1. LocalStorage is browser-specific\"}},{\"id\":\"NxIWuUAP4h\",\"type\":\"paragraph\",\"data\":{\"text\":\"If a customer adds a product on one browser, the same cart will not automatically appear on another browser or device.\"}},{\"id\":\"DMSMRPes1G\",\"type\":\"paragraph\",\"data\":{\"text\":\"2. LocalStorage is not a database\"}},{\"id\":\"WWOHh4hUaJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"It stores data inside the browser. It does not automatically synchronize with a server.\"}},{\"id\":\"lYWFxRU-hz\",\"type\":\"paragraph\",\"data\":{\"text\":\"3. Users can modify LocalStorage\"}},{\"id\":\"n4BqN0-seg\",\"type\":\"paragraph\",\"data\":{\"text\":\"A user can open browser developer tools and change stored values.\"}},{\"id\":\"aBCfFxfwN1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Therefore, a real e-commerce application must never trust LocalStorage for product prices, inventory, discounts, or payments.\"}},{\"id\":\"GwhOhxzu6c\",\"type\":\"paragraph\",\"data\":{\"text\":\"4. Real applications need backend validation\"}},{\"id\":\"_QGizTnOhJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"In a production application:\"}},{\"id\":\"r4UyHC7OHd\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Product data should come from an API or database.\",\"The backend should validate product prices.\",\"The backend should check stock availability.\",\"The backend should calculate the final order amount.\",\"The backend should process orders securely.\"]}},{\"id\":\"C1nUV56lYd\",\"type\":\"paragraph\",\"data\":{\"text\":\"LocalStorage is suitable for a frontend learning project and can be used for a guest cart, but it is not a secure order system.\"}},{\"id\":\"elvoPKxjAy\",\"type\":\"header\",\"data\":{\"text\":\"33. Common Mistakes Beginners Make\",\"level\":2}},{\"id\":\"IRFoVdUze4\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 1: Forgetting JSON.stringify()\",\"level\":3}},{\"id\":\"vT7YWQJyEQ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Incorrect:\"}},{\"id\":\"Rk5s4PLQ2M\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem(\\\"cart\\\", cart);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"7AznWV3Qxu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Correct:\"}},{\"id\":\"raqiMORgxf\",\"type\":\"code\",\"data\":{\"code\":\"localStorage.setItem(\\\"cart\\\", JSON.stringify(cart));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"mQ_ruCLpVp\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why? LocalStorage stores strings, so we convert the array into a JSON string first.\"}},{\"id\":\"A3u1fe24PE\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 2: Forgetting JSON.parse()\",\"level\":3}},{\"id\":\"t42Svoq7fB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Incorrect:\"}},{\"id\":\"gBQ5wozVwN\",\"type\":\"code\",\"data\":{\"code\":\"const cart = localStorage.getItem(\\\"cart\\\");\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"BpjbEs3tfo\",\"type\":\"paragraph\",\"data\":{\"text\":\"This returns a string, not a JavaScript array.\"}},{\"id\":\"WOYINFxvrH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Correct:\"}},{\"id\":\"fM1zCTHsY6\",\"type\":\"code\",\"data\":{\"code\":\"const cart = JSON.parse(localStorage.getItem(\\\"cart\\\"));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"4-r23ZRK4m\",\"type\":\"paragraph\",\"data\":{\"text\":\"Remember to handle the case where the key is missing or the saved JSON is invalid.\"}},{\"id\":\"W1HUKspclQ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Mistake 3: Using \"}},{\"id\":\"iXdf52ViLb\",\"type\":\"code\",\"data\":{\"code\":\"=\",\"language\":\"\",\"raw\":true}},{\"id\":\"Ue0SoH2-9Q\",\"type\":\"paragraph\",\"data\":{\"text\":\" Instead of \"}},{\"id\":\"8CDnVY4jql\",\"type\":\"code\",\"data\":{\"code\":\"===\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"wuSR8J_XL7\",\"type\":\"paragraph\",\"data\":{\"text\":\"Incorrect:\"}},{\"id\":\"TV1XzaRStj\",\"type\":\"code\",\"data\":{\"code\":\"product.category = selectedCategory;\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"QNuHbl7PUy\",\"type\":\"paragraph\",\"data\":{\"text\":\"Correct:\"}},{\"id\":\"_OYVhQK4aQ\",\"type\":\"code\",\"data\":{\"code\":\"product.category === selectedCategory;\",\"language\":\"ini\",\"raw\":true}},{\"id\":\"ATNdKgUqZJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"The first statement assigns a value. The second compares two values.\"}},{\"id\":\"l2GvW7WoE_\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 4: Sorting the Original Product Array\",\"level\":3}},{\"id\":\"IIPjwuFJzN\",\"type\":\"paragraph\",\"data\":{\"text\":\"Potentially problematic:\"}},{\"id\":\"VTRQP4Na_7\",\"type\":\"code\",\"data\":{\"code\":\"products.sort(function(a, b) {\\n    return a.price - b.price;\\n});\",\"language\":\"css\",\"raw\":true}},{\"id\":\"3To4ax-ryn\",\"type\":\"paragraph\",\"data\":{\"text\":\"Better:\"}},{\"id\":\"10sb1izGKi\",\"type\":\"code\",\"data\":{\"code\":\"const sortedProducts = [...products];\\n\\nsortedProducts.sort(function(a, b) {\\n    return a.price - b.price;\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"FN-Wf7OOz_\",\"type\":\"paragraph\",\"data\":{\"text\":\"This avoids changing the original array order.\"}},{\"id\":\"OTII0-DMQh\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 5: Not Updating LocalStorage\",\"level\":3}},{\"id\":\"zaWrSEOm9O\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you change the cart but do not call \"}},{\"id\":\"8NqiCqMA1g\",\"type\":\"code\",\"data\":{\"code\":\"saveCart()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Ka58sSfp3U\",\"type\":\"paragraph\",\"data\":{\"text\":\", the latest cart data will not be saved.\"}},{\"id\":\"W4-CpfTzlp\",\"type\":\"paragraph\",\"data\":{\"text\":\"Call it after every cart operation.\"}},{\"id\":\"5lA8qvsNnF\",\"type\":\"header\",\"data\":{\"text\":\"34. Practice Exercises for Students\",\"level\":2}},{\"id\":\"L8bVAWAZR1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now that you have built the project, try improving it yourself.\"}},{\"id\":\"KGSmPkMXZ9\",\"type\":\"header\",\"data\":{\"text\":\"Beginner Level\",\"level\":3}},{\"id\":\"2hmovfB6QQ\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Add five more products.\",\"Add a new category called Home Appliances.\",\"Add a product description.\",\"Display the total number of different products in the cart.\",\"Show an alert when a product is added to the cart.\"]}},{\"id\":\"onUMB-WFs9\",\"type\":\"header\",\"data\":{\"text\":\"Intermediate Level\",\"level\":3}},{\"id\":\"3ro7vSAQPC\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Add a discount percentage to each product.\",\"Display the original price and discounted price.\",\"Add sorting by product name.\",\"Add a filter for products above \u20b95,000.\",\"Add a button to remove all filters except the search term.\",\"Display a message when a product is successfully added to the cart.\"]}},{\"id\":\"mcRnuykmcZ\",\"type\":\"header\",\"data\":{\"text\":\"Advanced Level\",\"level\":3}},{\"id\":\"UOFf6kl812\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"Create a separate product details page.\",\"Add a wishlist feature using LocalStorage.\",\"Add pagination to display products in groups.\",\"Add a cart badge that updates without reloading the page.\",\"Add a checkout form.\",\"Connect the frontend to a Node.js and Express backend.\",\"Store products and orders in MongoDB or PostgreSQL.\",\"Add user authentication and save carts to the database.\"]}},{\"id\":\"l-XRuiHk3J\",\"type\":\"header\",\"data\":{\"text\":\"35. Interview Questions Based on This Project\",\"level\":2}},{\"id\":\"LnWHtdqWJ_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q1. What is LocalStorage in JavaScript?\"}},{\"id\":\"yIpURrNWM4\",\"type\":\"paragraph\",\"data\":{\"text\":\"LocalStorage is a browser storage mechanism that allows us to store key-value data as strings. The stored data remains available across page refreshes and browser sessions until it is removed.\"}},{\"id\":\"gFlaikt62_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q2. What is the difference between LocalStorage and SessionStorage?\"}},{\"id\":\"rSj38ycpOW\",\"type\":\"paragraph\",\"data\":{\"text\":\"LocalStorage persists until data is removed. SessionStorage is generally limited to the current browser tab session and is cleared when that tab's session ends.\"}},{\"id\":\"8Ph7TcWEdW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q3. Why do we use JSON.stringify()?\"}},{\"id\":\"lKiuOlZb4s\",\"type\":\"paragraph\",\"data\":{\"text\":\"We use \"}},{\"id\":\"DuzQV4pqli\",\"type\":\"code\",\"data\":{\"code\":\"JSON.stringify()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"IB9j4tgiOk\",\"type\":\"paragraph\",\"data\":{\"text\":\" to convert JavaScript objects or arrays into strings before saving them in LocalStorage.\"}},{\"id\":\"h0CACI_7Rk\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q4. Why do we use JSON.parse()?\"}},{\"id\":\"WT4oUXUVR3\",\"type\":\"paragraph\",\"data\":{\"text\":\"We use \"}},{\"id\":\"uIofjnn_6P\",\"type\":\"code\",\"data\":{\"code\":\"JSON.parse()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"ywguSGhhtD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q5. What is the difference between \"}},{\"id\":\"CwokjJbVHV\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"9OwDCUrCrQ\",\"type\":\"paragraph\",\"data\":{\"text\":\" and \"}},{\"id\":\"Mhd_-i_K5B\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"_xsqg34BoO\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ZhX6AZgqZc\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns a new array containing all matching elements. \"}},{\"id\":\"fHaxWTKZtH\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ihZOTCC_w8\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns the first matching element or \"}},{\"id\":\"CKoQuYBg0G\",\"type\":\"code\",\"data\":{\"code\":\"undefined\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"8CUC_0g16X\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q6. What is the difference between \"}},{\"id\":\"5V8uIyISUo\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"oaLldl0nTu\",\"type\":\"paragraph\",\"data\":{\"text\":\" and \"}},{\"id\":\"H49iE5lj63\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"2U-TJmZAq4\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"MknVuMdRZF\",\"type\":\"paragraph\",\"data\":{\"text\":\" creates and returns a new array containing transformed values. \"}},{\"id\":\"c0Sban6MqZ\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"tjwZ-ITRii\",\"type\":\"paragraph\",\"data\":{\"text\":\" executes a callback for each array item and does not create a new result array.\"}},{\"id\":\"dwNVGw2njB\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q7. Why do we use the spread operator before sorting?\"}},{\"id\":\"95Du1CkBfh\",\"type\":\"paragraph\",\"data\":{\"text\":\"The spread operator creates a shallow copy of an array. We use it because \"}},{\"id\":\"W5DvFoYKCd\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"qpkImSAMOS\",\"type\":\"paragraph\",\"data\":{\"text\":\" modifies the original array.\"}},{\"id\":\"9qa-3cHAYl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q8. How do you prevent duplicate products in a cart?\"}},{\"id\":\"LB5iL5mHzu\",\"type\":\"paragraph\",\"data\":{\"text\":\"We use \"}},{\"id\":\"1OzimZ_PR6\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"GUHvh8keo_\",\"type\":\"paragraph\",\"data\":{\"text\":\" to check whether a product ID already exists in the cart. If it exists, we increase its quantity instead of adding another entry.\"}},{\"id\":\"BzAifDqn1c\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q9. Why should we not trust prices stored in LocalStorage?\"}},{\"id\":\"g2LhkzbaVn\",\"type\":\"paragraph\",\"data\":{\"text\":\"Users can modify browser storage. A backend must validate product prices and calculate the final order amount before accepting an order.\"}},{\"id\":\"zqvRnQX29Q\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q10. What is event delegation?\"}},{\"id\":\"m3fX5mbSDu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Event delegation is a technique where we attach an event listener to a parent element and handle events from its child elements using event bubbling.\"}},{\"id\":\"1rJbh1-532\",\"type\":\"header\",\"data\":{\"text\":\"36. Related JavaScript Projects to Learn Next\",\"level\":2}},{\"id\":\"x5OcsgCJmt\",\"type\":\"paragraph\",\"data\":{\"text\":\"After completing this e-commerce project, you can build these projects to improve your JavaScript skills.\"}},{\"id\":\"UaX-O7JMA6\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"JavaScript Shopping Cart Project: Build a dedicated cart page with quantity management, subtotal, tax, and discounts.\",\"JavaScript Wishlist Project: Allow customers to save their favourite products using LocalStorage.\",\"JavaScript Product Details Page: Display product images, descriptions, ratings, and available variations.\",\"JavaScript Checkout Page: Create an address form, order summary, and checkout validation.\",\"JavaScript Todo Application: Learn CRUD operations, DOM manipulation, and LocalStorage.\",\"JavaScript Expense Tracker: Add expenses, categories, filters, and total calculations.\",\"JavaScript Weather Application: Learn how to fetch and display data from an API.\",\"MERN Stack E-commerce Application: Convert this frontend project into a full-stack application using React, Node.js, Express, and MongoDB.\"]}},{\"id\":\"SnJIIXbnwz\",\"type\":\"header\",\"data\":{\"text\":\"37. Conclusion\",\"level\":2}},{\"id\":\"_QkB8Y2J93\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this project, we built a practical JavaScript e-commerce product page with multiple features.\"}},{\"id\":\"AmKF5Vbhe2\",\"type\":\"paragraph\",\"data\":{\"text\":\"We learned how to:\"}},{\"id\":\"VDtqd8fcj4\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"Store products using arrays and objects.\",\"Display product cards dynamically.\",\"Search products using JavaScript.\",\"Filter products by category, price, rating, and stock.\",\"Sort products by price and rating.\",\"Add products to a shopping cart.\",\"Prevent duplicate cart entries.\",\"Increase and decrease product quantities.\",\"Remove products from the cart.\",\"Calculate the total cart price.\",\"Save and restore cart data using LocalStorage.\"]}},{\"id\":\"QJUyUzok4z\",\"type\":\"paragraph\",\"data\":{\"text\":\"The most important lesson is that JavaScript becomes easier to understand when you use its concepts to solve real problems.\"}},{\"id\":\"OPBzP4MsTm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Don't just copy the code. Try changing the product data, adding new filters, and building additional features. This is how you develop practical JavaScript skills.\"}},{\"id\":\"2ItzHGaS2W\",\"type\":\"header\",\"data\":{\"text\":\"SEO Details for SamWithCode\",\"level\":2}},{\"id\":\"YArb6j6JfC\",\"type\":\"paragraph\",\"data\":{\"text\":\"SEO Title:\"}},{\"id\":\"zvMTe3qRSP\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript E-commerce Product Page Project \u2013 Search, Filter, Sort &amp; Add to Cart\"}},{\"id\":\"OlsweHUo9m\",\"type\":\"paragraph\",\"data\":{\"text\":\"Meta Description:\"}},{\"id\":\"z9yPWhZeqZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Build a complete e-commerce product page using HTML, CSS, and JavaScript. Learn product search, category filters, price range, sorting, ratings, Add to Cart, quantity management, and LocalStorage with complete source code.\"}},{\"id\":\"Xrye26zoMs\",\"type\":\"paragraph\",\"data\":{\"text\":\"URL Slug:\"}},{\"id\":\"W87dkv0qHS\",\"type\":\"code\",\"data\":{\"code\":\"javascript-ecommerce-product-page-project\",\"language\":\"\",\"raw\":true}},{\"id\":\"ZtByP2B7EG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Primary Focus Keyword:\"}},{\"id\":\"RZXcJEC3FI\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript E-commerce Project\"}},{\"id\":\"I9cFnULgGO\",\"type\":\"paragraph\",\"data\":{\"text\":\"Secondary Keywords:\"}},{\"id\":\"JSR4UBHMNk\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"JavaScript product filter project\",\"JavaScript search and sort products\",\"JavaScript Add to Cart with LocalStorage\",\"JavaScript price range filter\",\"JavaScript shopping cart project\",\"JavaScript product listing page\",\"JavaScript DOM manipulation project\",\"JavaScript projects for beginners\"]}},{\"id\":\"AYEyjqFMri\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suggested Blog Category:\"}},{\"id\":\"8DK4UPqQGA\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript Projects\"}},{\"id\":\"XsPoCYWlLT\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suggested Tags:\"}},{\"id\":\"NgZkXJIuQc\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript, HTML, CSS, E-commerce Project, Add to Cart, LocalStorage, DOM Manipulation, JavaScript Projects, Shopping Cart\"}},{\"id\":\"ewqvRBEysC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suggested Featured Image Text:\"}},{\"id\":\"ULqXnSHN8J\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript E-commerce Product Page\"}},{\"id\":\"PkvKRFVRBL\",\"type\":\"paragraph\",\"data\":{\"text\":\"Search | Filter | Sort | Add to Cart | LocalStorage\"}},{\"id\":\"YNHEuiIh93\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suggested Internal Links:\"}},{\"id\":\"AYYCIlA9YF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Link this article to your related SamWithCode tutorials:\"}},{\"id\":\"ES76atGEfJ\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"JavaScript Array Methods\",\"JavaScript Objects\",\"JavaScript DOM Manipulation\",\"JavaScript Events and Event Listeners\",\"JavaScript LocalStorage\",\"JavaScript JSON Methods\",\"JavaScript Filter Method\",\"JavaScript Sort Method\"]}},{\"id\":\"Ua1g759TR2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suggested Next Blog:\"}},{\"id\":\"eRE8596wDw\",\"type\":\"paragraph\",\"data\":{\"text\":\"Build a Complete JavaScript Shopping Cart Page \u2013 Quantity, Discount, Tax &amp; Checkout\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/javascript-e-commerce-product-page-project-search-filter-sort-add-to-cart-using-localstorage-1795239810.jfif","status":"published","excerpt":"Learn to build a JavaScript e-commerce product page with search, category and price filters, sorting, ratings, Add to Cart, and LocalStorage. Includes complete source code.","published_at":"2026-11-21T05:42:45.000000Z","tags":"[\"js\",\"javascript\",\"add to cart\",\"web development\",\"frontend\",\"filter\",\"e-commerce\"]","created_at":"2026-11-21T05:42:45.000000Z","updated_at":"2026-11-27T14:22:10.000000Z","views":12,"scheduled_at":null,"score":1795239789},{"id":15,"user_id":1,"category_id":2,"title":"JavaScript Array Methods Explained with Examples (Complete Guide)","slug":"javascript-array-methods","content":"{\"time\":1794718401109,\"blocks\":[{\"id\":\"mvLTdHXA-R\",\"type\":\"header\",\"data\":{\"text\":\"JavaScript Array Methods Explained with Examples (Complete Guide)\",\"level\":2}},{\"id\":\"2lCYxn1-X5\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript arrays are one of the most important concepts in modern web development. Whether you are building a shopping cart, managing user data, displaying products, or working with APIs, you will frequently use arrays to store and manipulate information.\"}},{\"id\":\"9qU5WtNczJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript provides many built-in array methods that make it easier to add, remove, search, transform, filter, and organize data.\"}},{\"id\":\"FHvCHQeTAU\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this tutorial, you will learn:\"}},{\"id\":\"uEeH-UdZxU\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"What JavaScript arrays are and how to create them.\",\"How to access, update, and loop through array elements.\",\"Important JavaScript array methods with practical examples.\",\"The difference between <code>map()<\/code>, <code>filter()<\/code>, and <code>reduce()<\/code>.\",\"The difference between <code>slice()<\/code> and <code>splice()<\/code>.\",\"How to sort, search, and transform arrays.\",\"Modern JavaScript array methods.\",\"Real-world examples, exercises, and interview questions.\"]}},{\"id\":\"NUIVcmoXsb\",\"type\":\"paragraph\",\"data\":{\"text\":\"By the end, you will understand how to work with JavaScript arrays confidently in real projects.\"}},{\"id\":\"oBbI32Dw0U\",\"type\":\"header\",\"data\":{\"text\":\"1. What Is an Array in JavaScript?\",\"level\":2}},{\"id\":\"asRHtBUxlq\",\"type\":\"paragraph\",\"data\":{\"text\":\"An array is a data structure used to store multiple values inside a single variable.\"}},{\"id\":\"nYUfaUAbtZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead of creating separate variables for every value, you can store related information together in an array.\"}},{\"id\":\"_pCtOzzIKP\",\"type\":\"image\",\"data\":{\"file\":{\"url\":\"https:\/\/samwithcode.com\/storage\/content\/blogs\/utbIGfaQwAUuuz9BqGvf5FEPQHlNreQjXB2or0kT.jpg\"},\"caption\":\"\",\"withBorder\":false,\"stretched\":false,\"withBackground\":false}},{\"id\":\"ByxD6pU_Xq\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example, imagine you want to store the names of five students.\"}},{\"id\":\"72PhY3y6Ip\",\"type\":\"paragraph\",\"data\":{\"text\":\"Without an array:\"}},{\"id\":\"IectmuULqu\",\"type\":\"code\",\"data\":{\"code\":\"const student1 = \\\"Aman\\\";\\nconst student2 = \\\"Rahul\\\";\\nconst student3 = \\\"Priya\\\";\\nconst student4 = \\\"Neha\\\";\\nconst student5 = \\\"Rohit\\\";\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Prw4vxgoyA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Using an array:\"}},{\"id\":\"kErDtPyBSp\",\"type\":\"code\",\"data\":{\"code\":\"const students = [\\\"Aman\\\", \\\"Rahul\\\", \\\"Priya\\\", \\\"Neha\\\", \\\"Rohit\\\"];\\n\\nconsole.log(students);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"-rDZaLPiXL\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"bimOgiOGUR\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Aman\\\", \\\"Rahul\\\", \\\"Priya\\\", \\\"Neha\\\", \\\"Rohit\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"cVhyq5jzSE\",\"type\":\"paragraph\",\"data\":{\"text\":\"An array makes data easier to manage, access, and process.\"}},{\"id\":\"ZKSi92xiZF\",\"type\":\"header\",\"data\":{\"text\":\"JavaScript Array Syntax\",\"level\":3}},{\"id\":\"28KptexBIa\",\"type\":\"code\",\"data\":{\"code\":\"const arrayName = [value1, value2, value3];\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"yz1FRrfLz4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"qWyTE6tyrs\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nconsole.log(fruits);\\nconsole.log(typeof fruits);\\nconsole.log(Array.isArray(fruits));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"0dW-6L3f5A\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"6DQRuJ4A4h\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\\nobject\\ntrue\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"FY0d3axPLg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Remember: JavaScript arrays have the type \"}},{\"id\":\"rqRgLP0dbk\",\"type\":\"code\",\"data\":{\"code\":\"object\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"XPB1SGbvab\",\"type\":\"paragraph\",\"data\":{\"text\":\". Use \"}},{\"id\":\"uXIDbx10aY\",\"type\":\"code\",\"data\":{\"code\":\"Array.isArray()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"0vTtjMCz3b\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you need to check whether a value is an array.\"}},{\"id\":\"luBQYxRt-T\",\"type\":\"header\",\"data\":{\"text\":\"2. How to Create Arrays in JavaScript\",\"level\":2}},{\"id\":\"NN2-p3VtUw\",\"type\":\"paragraph\",\"data\":{\"text\":\"There are multiple ways to create arrays in JavaScript.\"}},{\"id\":\"vfl-fz9Quz\",\"type\":\"header\",\"data\":{\"text\":\"Method 1: Using Array Literals\",\"level\":3}},{\"id\":\"1NE3-xI8W4\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is the most common and recommended way to create an array.\"}},{\"id\":\"04orJi1jwe\",\"type\":\"code\",\"data\":{\"code\":\"const languages = [\\\"JavaScript\\\", \\\"Python\\\", \\\"Java\\\", \\\"PHP\\\"];\\n\\nconsole.log(languages);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"IF4WS0ldEv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"sAEEibMChb\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"JavaScript\\\", \\\"Python\\\", \\\"Java\\\", \\\"PHP\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"XNWux28dTs\",\"type\":\"header\",\"data\":{\"text\":\"Method 2: Using the Array Constructor\",\"level\":3}},{\"id\":\"5w21XO-nIj\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can also create an array using the \"}},{\"id\":\"h0uF_FSNJv\",\"type\":\"code\",\"data\":{\"code\":\"Array()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"fQN74VSlIW\",\"type\":\"paragraph\",\"data\":{\"text\":\" constructor.\"}},{\"id\":\"LkJp40Mxg0\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = new Array(10, 20, 30, 40);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"J0Vqb_Qb0v\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"gHwiVTC0T9\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30, 40]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"91eKWEfit4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Be careful when passing a single number to the constructor:\"}},{\"id\":\"UTs8v5bPZj\",\"type\":\"code\",\"data\":{\"code\":\"const items = new Array(5);\\n\\nconsole.log(items.length);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"A-lWl_YnZd\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"HeuWSLUjka\",\"type\":\"code\",\"data\":{\"code\":\"5\",\"language\":\"\",\"raw\":true}},{\"id\":\"tFkIM1PrRF\",\"type\":\"paragraph\",\"data\":{\"text\":\"This creates an array with five empty slots, not an array containing the number \"}},{\"id\":\"lyvu6445_0\",\"type\":\"code\",\"data\":{\"code\":\"5\",\"language\":\"\",\"raw\":true}},{\"id\":\"bJpN82wi-J\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"0wFrmWK4jt\",\"type\":\"header\",\"data\":{\"text\":\"Method 3: Using Array.of()\",\"level\":3}},{\"id\":\"TYg8gjr4Hh\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"Fkesus4zbU\",\"type\":\"code\",\"data\":{\"code\":\"Array.of()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"yAPoHbdZHL\",\"type\":\"paragraph\",\"data\":{\"text\":\" method creates an array using the supplied arguments.\"}},{\"id\":\"KoFtYoOx9i\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = Array.of(5);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"147S58X56F\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"urB-a7F-KS\",\"type\":\"code\",\"data\":{\"code\":\"[5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"iHH_UHHSqD\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is different from \"}},{\"id\":\"0I-qjMwD8r\",\"type\":\"code\",\"data\":{\"code\":\"new Array(5)\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"PWbzxGKWZe\",\"type\":\"paragraph\",\"data\":{\"text\":\", which creates an array with five empty slots.\"}},{\"id\":\"RLhuIpcFSw\",\"type\":\"header\",\"data\":{\"text\":\"3. Understanding Array Indexes\",\"level\":2}},{\"id\":\"bSRLXN5g93\",\"type\":\"paragraph\",\"data\":{\"text\":\"Every element in a JavaScript array has an index.\"}},{\"id\":\"px5qEcBSbe\",\"type\":\"paragraph\",\"data\":{\"text\":\"Array indexes start from \"}},{\"id\":\"9kSz9iIG3P\",\"type\":\"code\",\"data\":{\"code\":\"0\",\"language\":\"\",\"raw\":true}},{\"id\":\"WcZ88a46il\",\"type\":\"paragraph\",\"data\":{\"text\":\", not \"}},{\"id\":\"j9Jbn2KisC\",\"type\":\"code\",\"data\":{\"code\":\"1\",\"language\":\"\",\"raw\":true}},{\"id\":\"Q3E2xEZZiM\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"yvZmsZba3u\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"xRsAt92QZk\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"];\\n\\nconsole.log(fruits[0]);\\nconsole.log(fruits[1]);\\nconsole.log(fruits[2]);\\nconsole.log(fruits[3]);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"FdeLVDqd0s\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"M9eTka-TrR\",\"type\":\"code\",\"data\":{\"code\":\"Apple\\nBanana\\nMango\\nOrange\",\"language\":\"\",\"raw\":true}},{\"id\":\"cOxazO1jHo\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can visualize the indexes like this:\"}},{\"id\":\"JpZEJRAY5s\",\"type\":\"paragraph\",\"data\":{\"text\":\"IndexValue0Apple1Banana2Mango3Orange\"}},{\"id\":\"0YKxk0Cjvz\",\"type\":\"header\",\"data\":{\"text\":\"Accessing the Last Element\",\"level\":3}},{\"id\":\"qHvtX01nNN\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can use the \"}},{\"id\":\"cxijSYLOWA\",\"type\":\"code\",\"data\":{\"code\":\"length\",\"language\":\"perl\",\"raw\":true}},{\"id\":\"gSZWjlrlc1\",\"type\":\"paragraph\",\"data\":{\"text\":\" property to access the last element.\"}},{\"id\":\"ZgdkkgM8nN\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"];\\n\\nconsole.log(fruits[fruits.length - 1]);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"SbOPzDjObH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"6qSPeCdtGX\",\"type\":\"code\",\"data\":{\"code\":\"Orange\",\"language\":\"\",\"raw\":true}},{\"id\":\"IeZOkZjIrh\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can also use \"}},{\"id\":\"WS1RyYynvt\",\"type\":\"code\",\"data\":{\"code\":\"at()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"L1---6cak6\",\"type\":\"paragraph\",\"data\":{\"text\":\":\"}},{\"id\":\"fatBWlXV0O\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"];\\n\\nconsole.log(fruits.at(-1));\\nconsole.log(fruits.at(-2));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"ezCUwwvj8A\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"tRWylS20V3\",\"type\":\"code\",\"data\":{\"code\":\"Orange\\nMango\",\"language\":\"\",\"raw\":true}},{\"id\":\"HVLi7rofp2\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"0z9BvvFr8a\",\"type\":\"code\",\"data\":{\"code\":\"at()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"lpBwBVmBIj\",\"type\":\"paragraph\",\"data\":{\"text\":\" method supports negative indexes, making it convenient to access elements from the end.\"}},{\"id\":\"fAiMeFn3y3\",\"type\":\"header\",\"data\":{\"text\":\"4. How to Add and Update Array Elements\",\"level\":2}},{\"id\":\"QBI04CNrx9\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript allows you to modify arrays using indexes and built-in methods.\"}},{\"id\":\"vTLCOcezYM\",\"type\":\"header\",\"data\":{\"text\":\"Updating an Element\",\"level\":3}},{\"id\":\"d1NVYHBe3m\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits[1] = \\\"Orange\\\";\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"4gRbVK683Z\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"jXQnpSB_kG\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Orange\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"4rvrktnIdQ\",\"type\":\"header\",\"data\":{\"text\":\"Adding an Element Using an Index\",\"level\":3}},{\"id\":\"H2QcOwbn0i\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\"];\\n\\nfruits[2] = \\\"Mango\\\";\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"5l2IJhezvP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Eq9B3g6wEI\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"ECs2Q0t4-W\",\"type\":\"header\",\"data\":{\"text\":\"Adding an Element Using push()\",\"level\":3}},{\"id\":\"PH1fp13RsP\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"Q5U33W9p7Q\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"nNxcUV-kWV\",\"type\":\"paragraph\",\"data\":{\"text\":\" method adds one or more elements to the end of an array.\"}},{\"id\":\"sYMv1UaQdr\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\"];\\n\\nfruits.push(\\\"Mango\\\");\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"MuonEkbrrr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"AAv5qpJ9aU\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"VpvBOZFIHW\",\"type\":\"header\",\"data\":{\"text\":\"Adding an Element Using unshift()\",\"level\":3}},{\"id\":\"Hvbg_6EH3w\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"XMiUEYtERV\",\"type\":\"code\",\"data\":{\"code\":\"unshift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"wMFVmUm_qv\",\"type\":\"paragraph\",\"data\":{\"text\":\" method adds elements to the beginning of an array.\"}},{\"id\":\"yzlpGz4x31\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits.unshift(\\\"Apple\\\");\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"GkhtiMpPgK\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"mIR0Mc1Dj8\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"W8fKb23cOo\",\"type\":\"header\",\"data\":{\"text\":\"5. JavaScript Array Methods\",\"level\":2}},{\"id\":\"mkARWoVH9U\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript provides many built-in methods to manipulate and process array data.\"}},{\"id\":\"zYeruF8L2r\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's understand the most useful methods with examples.\"}},{\"id\":\"UijK1Zniql\",\"type\":\"header\",\"data\":{\"text\":\"5.1 push()\",\"level\":3}},{\"id\":\"O-6RMud3-_\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"54YTuhGtJB\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"7IqCZzOqvc\",\"type\":\"paragraph\",\"data\":{\"text\":\" method adds one or more elements to the end of an array.\"}},{\"id\":\"zggOU4TLCP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Syntax:\"}},{\"id\":\"eMneqB04-S\",\"type\":\"code\",\"data\":{\"code\":\"array.push(element1, element2, ...);\",\"language\":\"php\",\"raw\":true}},{\"id\":\"ruNpzFuoT9\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"Dx16KYm146\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30];\\n\\nnumbers.push(40, 50);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"dJWDTiIgrs\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"T6EIQbEOIa\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30, 40, 50]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"qXUtm0A_4T\",\"type\":\"paragraph\",\"data\":{\"text\":\"Important: \"}},{\"id\":\"cu9HS8fmxG\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"CPFCT23na3\",\"type\":\"paragraph\",\"data\":{\"text\":\" modifies the original array and returns the new array length.\"}},{\"id\":\"9bbk3OriyA\",\"type\":\"header\",\"data\":{\"text\":\"5.2 pop()\",\"level\":3}},{\"id\":\"19tu5qz8nu\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"Wd-tDrqK7s\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5gPvb4DhUQ\",\"type\":\"paragraph\",\"data\":{\"text\":\" method removes the last element from an array.\"}},{\"id\":\"QSyeR3WVnx\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nconst removedValue = numbers.pop();\\n\\nconsole.log(numbers);\\nconsole.log(removedValue);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"D68vg3XLNz\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"x6XrBPHCtD\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30]\\n40\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"7tGKz1yDNf\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"_e3Q7mwAtV\",\"type\":\"paragraph\",\"data\":{\"text\":\" modifies the original array and returns the removed element.\"}},{\"id\":\"u5Qx0vhTs1\",\"type\":\"header\",\"data\":{\"text\":\"5.3 unshift()\",\"level\":3}},{\"id\":\"4-FWoqQEI4\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"UOnve8nS6n\",\"type\":\"code\",\"data\":{\"code\":\"unshift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"AVaaJ4qiBJ\",\"type\":\"paragraph\",\"data\":{\"text\":\" method adds one or more elements to the beginning of an array.\"}},{\"id\":\"l4Y2kVY3dM\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [20, 30, 40];\\n\\nnumbers.unshift(5, 10);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"oitCQe7Z4S\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"vNvPMsA-pX\",\"type\":\"code\",\"data\":{\"code\":\"[5, 10, 20, 30, 40]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"9OCXLYtVSI\",\"type\":\"header\",\"data\":{\"text\":\"5.4 shift()\",\"level\":3}},{\"id\":\"JfEeXF5Rf2\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"9CvdI8jQep\",\"type\":\"code\",\"data\":{\"code\":\"shift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"1DLXQtlzbO\",\"type\":\"paragraph\",\"data\":{\"text\":\" method removes the first element from an array.\"}},{\"id\":\"sIGOnO5o7Y\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nconst removedValue = numbers.shift();\\n\\nconsole.log(numbers);\\nconsole.log(removedValue);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"I8cneUnrsf\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"nYVKtp0Kbg\",\"type\":\"code\",\"data\":{\"code\":\"[20, 30, 40]\\n10\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"fusiWY-D8o\",\"type\":\"header\",\"data\":{\"text\":\"5.5 splice()\",\"level\":3}},{\"id\":\"rJTS-iBCIo\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"fGSaX32Q_e\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"A96rRnboRD\",\"type\":\"paragraph\",\"data\":{\"text\":\" method can add, remove, or replace elements at specific positions in an array.\"}},{\"id\":\"--PnHeDDAy\",\"type\":\"paragraph\",\"data\":{\"text\":\"Syntax:\"}},{\"id\":\"QPtdRhjAbn\",\"type\":\"code\",\"data\":{\"code\":\"array.splice(start, deleteCount, item1, item2, ...);\",\"language\":\"php\",\"raw\":true}},{\"id\":\"wU7DsrF_LP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example: Removing elements.\"}},{\"id\":\"n_lO0ND4Al\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"];\\n\\nfruits.splice(1, 2);\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"0fqD1vhCa_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"ml7ZReDMz9\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Orange\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"Vh_-MLHLtH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example: Adding elements.\"}},{\"id\":\"kSoulrwMcq\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Orange\\\"];\\n\\nfruits.splice(1, 0, \\\"Banana\\\", \\\"Mango\\\");\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"RkANd4yx4n\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"gQ_ecHl2FP\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"xHizu1DQes\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example: Replacing an element.\"}},{\"id\":\"sqnDodtI1f\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits.splice(1, 1, \\\"Orange\\\");\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"xZQcjusEmd\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"or_h_QxM1O\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Orange\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"VGWHl7YVXD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Important: \"}},{\"id\":\"4fXFqTvG7H\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"zA3QNor83K\",\"type\":\"paragraph\",\"data\":{\"text\":\" modifies the original array.\"}},{\"id\":\"OCHKt8Vv5C\",\"type\":\"header\",\"data\":{\"text\":\"5.6 slice()\",\"level\":3}},{\"id\":\"CUJTgYVoV_\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"BKk43rSM37\",\"type\":\"code\",\"data\":{\"code\":\"slice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"KM4FbjbnGe\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a shallow copy of a portion of an array without modifying the original array.\"}},{\"id\":\"P96C7J2Wk7\",\"type\":\"paragraph\",\"data\":{\"text\":\"Syntax:\"}},{\"id\":\"r918gmTSuy\",\"type\":\"code\",\"data\":{\"code\":\"array.slice(start, end);\",\"language\":\"sql\",\"raw\":true}},{\"id\":\"iGqBXKf8Nc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example:\"}},{\"id\":\"8FmYBNK0sS\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"];\\n\\nconst selectedFruits = fruits.slice(1, 3);\\n\\nconsole.log(selectedFruits);\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"JBIT2Ar9VJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"PFLtgpn1FK\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Banana\\\", \\\"Mango\\\"]\\n[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Orange\\\"]\",\"language\":\"css\",\"raw\":true}},{\"id\":\"rcvWTZKXKs\",\"type\":\"paragraph\",\"data\":{\"text\":\"The ending index is excluded.\"}},{\"id\":\"_8Y-QpgAb8\",\"type\":\"header\",\"data\":{\"text\":\"Difference Between slice() and splice()\",\"level\":3}},{\"id\":\"qy_Zxx90gc\",\"type\":\"paragraph\",\"data\":{\"text\":\"slice()splice()Returns a shallow copyReturns removed elementsDoes not modify original arrayModifies original arrayUsed to extract elementsUsed to add, remove, or replace elementsDoes not change array lengthCan change array length\"}},{\"id\":\"TJtG0wLYAn\",\"type\":\"header\",\"data\":{\"text\":\"5.7 concat()\",\"level\":3}},{\"id\":\"U8j_VsCvap\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"latt6KjIHA\",\"type\":\"code\",\"data\":{\"code\":\"concat()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"gU7LRRqHAv\",\"type\":\"paragraph\",\"data\":{\"text\":\" method joins two or more arrays and returns a new array.\"}},{\"id\":\"3XaHBhDTlw\",\"type\":\"code\",\"data\":{\"code\":\"const frontend = [\\\"HTML\\\", \\\"CSS\\\", \\\"JavaScript\\\"];\\nconst backend = [\\\"Node.js\\\", \\\"Python\\\"];\\n\\nconst technologies = frontend.concat(backend);\\n\\nconsole.log(technologies);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"0rGdjaKqk4\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"3j4tqpKw-f\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"HTML\\\", \\\"CSS\\\", \\\"JavaScript\\\", \\\"Node.js\\\", \\\"Python\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"z74UQLz6QC\",\"type\":\"paragraph\",\"data\":{\"text\":\"The original arrays remain unchanged.\"}},{\"id\":\"hd32ameP_x\",\"type\":\"header\",\"data\":{\"text\":\"5.8 join()\",\"level\":3}},{\"id\":\"CEVYTmpB92\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"EeG1jJViyD\",\"type\":\"code\",\"data\":{\"code\":\"join()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"dvU4NnTjJf\",\"type\":\"paragraph\",\"data\":{\"text\":\" method converts array elements into a string using a specified separator.\"}},{\"id\":\"YZuDx9nYqY\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nconsole.log(fruits.join(\\\", \\\"));\\nconsole.log(fruits.join(\\\" - \\\"));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"wHb2aC43-z\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Hh6XrtY3Jc\",\"type\":\"code\",\"data\":{\"code\":\"Apple, Banana, Mango\\nApple - Banana - Mango\",\"language\":\"\",\"raw\":true}},{\"id\":\"EiFlZK88eT\",\"type\":\"header\",\"data\":{\"text\":\"5.9 reverse()\",\"level\":3}},{\"id\":\"baOHghRs4b\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"ohO2X7xocJ\",\"type\":\"code\",\"data\":{\"code\":\"reverse()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"j-E3BqBUM5\",\"type\":\"paragraph\",\"data\":{\"text\":\" method reverses the order of elements in an array.\"}},{\"id\":\"9Ifh1IDlZc\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nnumbers.reverse();\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"1Q4KSOhI97\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"WF29l70fq3\",\"type\":\"code\",\"data\":{\"code\":\"[40, 30, 20, 10]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"66mwBH0uOW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Important: \"}},{\"id\":\"ZCtGB7g1Bk\",\"type\":\"code\",\"data\":{\"code\":\"reverse()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ul7tlEvGV_\",\"type\":\"paragraph\",\"data\":{\"text\":\" modifies the original array.\"}},{\"id\":\"Fg00D_fxmB\",\"type\":\"header\",\"data\":{\"text\":\"5.10 sort()\",\"level\":3}},{\"id\":\"s4QavaO2jF\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"At2WGl-wRg\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"pdA0vad-Vz\",\"type\":\"paragraph\",\"data\":{\"text\":\" method sorts the elements of an array.\"}},{\"id\":\"VtzMSZnkTq\",\"type\":\"paragraph\",\"data\":{\"text\":\"By default, JavaScript sorts elements as strings.\"}},{\"id\":\"RhNrZz-TWP\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Mango\\\", \\\"Apple\\\", \\\"Banana\\\"];\\n\\nfruits.sort();\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"aWm17PYhPM\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"4vuY8sHXYC\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"YY_0FRqSRh\",\"type\":\"paragraph\",\"data\":{\"text\":\"For numbers, use a comparison function.\"}},{\"id\":\"kGtE2qHRdD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Incorrect numeric sorting without a comparator:\"}},{\"id\":\"3pjJzzOF55\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [100, 5, 25, 10];\\n\\nnumbers.sort();\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"49SzNqWHnZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"rxFkSXUo1Y\",\"type\":\"code\",\"data\":{\"code\":\"[10, 100, 25, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"0pk8hbXOcS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Correct numeric sorting in ascending order:\"}},{\"id\":\"xgw4p704zM\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [100, 5, 25, 10];\\n\\nnumbers.sort((a, b) =&gt; a - b);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"7YWmDJ21AX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"dleBqVQNjh\",\"type\":\"code\",\"data\":{\"code\":\"[5, 10, 25, 100]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"YmqlK-k-LX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Descending order:\"}},{\"id\":\"ZO1_acdlWO\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [100, 5, 25, 10];\\n\\nnumbers.sort((a, b) =&gt; b - a);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"3W657fbs_R\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"va6Rl14G7-\",\"type\":\"code\",\"data\":{\"code\":\"[100, 25, 10, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"wazjHyKdEn\",\"type\":\"header\",\"data\":{\"text\":\"5.11 includes()\",\"level\":3}},{\"id\":\"2pUlpYdCvN\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"K_mFKPI0Xf\",\"type\":\"code\",\"data\":{\"code\":\"includes()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"r2vRI-KIZj\",\"type\":\"paragraph\",\"data\":{\"text\":\"It returns \"}},{\"id\":\"UKKYtcfcVX\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"wL4S-NVS5I\",\"type\":\"paragraph\",\"data\":{\"text\":\" or \"}},{\"id\":\"hs0yiB0fQf\",\"type\":\"code\",\"data\":{\"code\":\"false\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"EH-1rNS6jo\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"e9Ha_KyGmq\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nconsole.log(fruits.includes(\\\"Banana\\\"));\\nconsole.log(fruits.includes(\\\"Orange\\\"));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"qXuwL449A1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"bpDFl6iIan\",\"type\":\"code\",\"data\":{\"code\":\"true\\nfalse\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"8H0OQsq_bz\",\"type\":\"header\",\"data\":{\"text\":\"5.12 indexOf()\",\"level\":3}},{\"id\":\"X1W3NhZcvB\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"HfArhvR-lM\",\"type\":\"code\",\"data\":{\"code\":\"indexOf()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"p3a8128u4e\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns the first index of a specified element. If the element is not found, it returns \"}},{\"id\":\"dA_zt0uauZ\",\"type\":\"code\",\"data\":{\"code\":\"-1\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"WK7kT6_MXR\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"RiQxdA_Zld\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\", \\\"Banana\\\"];\\n\\nconsole.log(fruits.indexOf(\\\"Banana\\\"));\\nconsole.log(fruits.indexOf(\\\"Orange\\\"));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"XAoJIQQL6Q\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Lojt41dWJl\",\"type\":\"code\",\"data\":{\"code\":\"1\\n-1\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"mNg2ClP6i1\",\"type\":\"header\",\"data\":{\"text\":\"5.13 lastIndexOf()\",\"level\":3}},{\"id\":\"2Yie7wXMgI\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"-1PWolXb57\",\"type\":\"code\",\"data\":{\"code\":\"lastIndexOf()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Xw-OcMLXKT\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns the last index of a specified element.\"}},{\"id\":\"Mf7cJFWiaC\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 20, 40];\\n\\nconsole.log(numbers.lastIndexOf(20));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"1PNiFMCiql\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"opT7XkfP9u\",\"type\":\"code\",\"data\":{\"code\":\"3\",\"language\":\"\",\"raw\":true}},{\"id\":\"D5eBUPWUDx\",\"type\":\"header\",\"data\":{\"text\":\"5.14 find()\",\"level\":3}},{\"id\":\"1StKebvDE2\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"lTqJLH01uI\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"cPE58aZ5pt\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns the first element that satisfies a condition.\"}},{\"id\":\"-aNQzeTV13\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [5, 12, 18, 25, 30];\\n\\nconst result = numbers.find((number) =&gt; number &gt; 15);\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"xrBWSiktBS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"IwKZ1ecOnr\",\"type\":\"code\",\"data\":{\"code\":\"18\",\"language\":\"\",\"raw\":true}},{\"id\":\"kvu2RMIqZt\",\"type\":\"paragraph\",\"data\":{\"text\":\"If no element matches, \"}},{\"id\":\"0BgrOjhVX_\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"m3NenKzKUP\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns \"}},{\"id\":\"ALjj16Bm2Z\",\"type\":\"code\",\"data\":{\"code\":\"undefined\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"H3fHp-gWOU\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"3AggFAXlkk\",\"type\":\"header\",\"data\":{\"text\":\"5.15 findIndex()\",\"level\":3}},{\"id\":\"NTLcnW9-C7\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"ubSCzHxivq\",\"type\":\"code\",\"data\":{\"code\":\"findIndex()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"tVVS1FJHes\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns the index of the first element that satisfies a condition.\"}},{\"id\":\"1j3HK1K8Ol\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [5, 12, 18, 25, 30];\\n\\nconst result = numbers.findIndex((number) =&gt; number &gt; 15);\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"svXFmH749l\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"0j-3hbahtb\",\"type\":\"code\",\"data\":{\"code\":\"2\",\"language\":\"\",\"raw\":true}},{\"id\":\"31byAlOjGg\",\"type\":\"paragraph\",\"data\":{\"text\":\"If no element matches, it returns \"}},{\"id\":\"Z8y0srA_us\",\"type\":\"code\",\"data\":{\"code\":\"-1\",\"language\":\"diff\",\"raw\":true}},{\"id\":\"n8dmh86dnf\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"7FVoarvc73\",\"type\":\"header\",\"data\":{\"text\":\"5.16 filter()\",\"level\":3}},{\"id\":\"dNl5UgKFPQ\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"Qk-_1BL_Hn\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"nRDnf37hFF\",\"type\":\"paragraph\",\"data\":{\"text\":\" method creates a new array containing all elements that satisfy a condition.\"}},{\"id\":\"YTyS31yp6G\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 15, 20, 25, 30, 35];\\n\\nconst evenNumbers = numbers.filter((number) =&gt; number % 2 === 0);\\n\\nconsole.log(evenNumbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"oR-1Zzi55b\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"3Lg_flBOYv\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"b8GQLGX4iJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unlike \"}},{\"id\":\"8zA-7b9j8y\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"ll_Zv-NoIE\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"Msr13ikUn7\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"KQYy3nEquq\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns all matching elements.\"}},{\"id\":\"senb1cbku3\",\"type\":\"header\",\"data\":{\"text\":\"5.17 map()\",\"level\":3}},{\"id\":\"ZzWs8hY61p\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"2SODmkDlG2\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5LS5Tx3p9o\",\"type\":\"paragraph\",\"data\":{\"text\":\" method creates a new array by transforming every element of an existing array.\"}},{\"id\":\"fOUOSz6ePV\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4, 5];\\n\\nconst doubledNumbers = numbers.map((number) =&gt; number * 2);\\n\\nconsole.log(doubledNumbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"9icbWQEBHU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"3aTf3WuS1Q\",\"type\":\"code\",\"data\":{\"code\":\"[2, 4, 6, 8, 10]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"iePgeWaxIE\",\"type\":\"paragraph\",\"data\":{\"text\":\"The original array remains unchanged.\"}},{\"id\":\"wEyOnxWI0E\",\"type\":\"header\",\"data\":{\"text\":\"5.18 forEach()\",\"level\":3}},{\"id\":\"OiwJkDfv4N\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"yBfUryorGX\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"vvq5_kxbnj\",\"type\":\"paragraph\",\"data\":{\"text\":\" method executes a callback function once for each array element.\"}},{\"id\":\"zgb6SXtHCJ\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits.forEach((fruit, index) =&gt; {\\n    console.log(index, fruit);\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Lscj6woyOR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"vD1bCJ7c_1\",\"type\":\"code\",\"data\":{\"code\":\"0 Apple\\n1 Banana\\n2 Mango\",\"language\":\"\",\"raw\":true}},{\"id\":\"IB0_-P6YZF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unlike \"}},{\"id\":\"DBFNfeFt4-\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"S7TGY4B8lw\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"9k4Az1Q5mZ\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Y5RU7b7wne\",\"type\":\"paragraph\",\"data\":{\"text\":\" does not return a new array. Its return value is \"}},{\"id\":\"B30yY4h94E\",\"type\":\"code\",\"data\":{\"code\":\"undefined\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Hwh5CJUrLh\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"dzoPt9ibje\",\"type\":\"header\",\"data\":{\"text\":\"5.19 reduce()\",\"level\":3}},{\"id\":\"O2hg8hzpHl\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"ARsM1hg38X\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"RVT4zCzYwU\",\"type\":\"paragraph\",\"data\":{\"text\":\" method processes array elements and combines them into a single accumulated result.\"}},{\"id\":\"_ALwThfCv8\",\"type\":\"paragraph\",\"data\":{\"text\":\"It is commonly used for calculating totals, averages, grouping data, and more.\"}},{\"id\":\"j7kzq4Vry_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Syntax:\"}},{\"id\":\"-4u92knoHQ\",\"type\":\"code\",\"data\":{\"code\":\"array.reduce((accumulator, currentValue) =&gt; {\\n    \/\/ Return updated accumulator\\n}, initialValue);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"-IoLR3kMyG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example: Calculate the sum of numbers.\"}},{\"id\":\"fJ1PJ7PlzQ\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nconst total = numbers.reduce((sum, number) =&gt; {\\n    return sum + number;\\n}, 0);\\n\\nconsole.log(total);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"4sMuLpNcJs\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"f4g1fUwM4d\",\"type\":\"code\",\"data\":{\"code\":\"100\",\"language\":\"\",\"raw\":true}},{\"id\":\"kLg7szKKqv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here:\"}},{\"id\":\"EjBab_gFO1\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<code>sum<\/code> is the accumulator.\",\"<code>number<\/code> is the current element.\",\"<code>0<\/code> is the initial value.\"]}},{\"id\":\"yXz_4c7Kg1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Example: Calculate the total price of products.\"}},{\"id\":\"A-zejdwL9b\",\"type\":\"code\",\"data\":{\"code\":\"const products = [\\n    { name: \\\"Laptop\\\", price: 50000 },\\n    { name: \\\"Mouse\\\", price: 500 },\\n    { name: \\\"Keyboard\\\", price: 1500 }\\n];\\n\\nconst totalPrice = products.reduce((total, product) =&gt; {\\n    return total + product.price;\\n}, 0);\\n\\nconsole.log(totalPrice);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"6OC4R7-_HO\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"w-piMTfX8V\",\"type\":\"code\",\"data\":{\"code\":\"52000\",\"language\":\"\",\"raw\":true}},{\"id\":\"YLLmvnp5Nf\",\"type\":\"header\",\"data\":{\"text\":\"5.20 some()\",\"level\":3}},{\"id\":\"hg5MmIk8qP\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"Pdr4f-bBw0\",\"type\":\"code\",\"data\":{\"code\":\"some()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"XHu5uknsDL\",\"type\":\"paragraph\",\"data\":{\"text\":\" method checks whether at least one element satisfies a condition.\"}},{\"id\":\"GbD2mT4CSt\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 3, 5, 8, 9];\\n\\nconst hasEvenNumber = numbers.some((number) =&gt; number % 2 === 0);\\n\\nconsole.log(hasEvenNumber);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"OB7ISuO6es\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"z0boOYGTpu\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"6wiJL6OJH7\",\"type\":\"header\",\"data\":{\"text\":\"5.21 every()\",\"level\":3}},{\"id\":\"qEjfON2JJK\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"M-QE7VHRmI\",\"type\":\"code\",\"data\":{\"code\":\"every()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"7D-gcFUqsQ\",\"type\":\"paragraph\",\"data\":{\"text\":\" method checks whether all elements satisfy a condition.\"}},{\"id\":\"q8MwrbafFo\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [2, 4, 6, 8];\\n\\nconst allEven = numbers.every((number) =&gt; number % 2 === 0);\\n\\nconsole.log(allEven);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"LoJ_7RbFjH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"74bYzcnnAK\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"VA5jmT-b_D\",\"type\":\"paragraph\",\"data\":{\"text\":\"If even one element fails the condition, \"}},{\"id\":\"KNiDftHrLu\",\"type\":\"code\",\"data\":{\"code\":\"every()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5KllaRCbsF\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns \"}},{\"id\":\"NEY80LX-7n\",\"type\":\"code\",\"data\":{\"code\":\"false\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"UlRqq12YGx\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"9KKN9V6oAf\",\"type\":\"header\",\"data\":{\"text\":\"5.22 flat()\",\"level\":3}},{\"id\":\"VswpzNYNgI\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"ICINT_N0qi\",\"type\":\"code\",\"data\":{\"code\":\"flat()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"7blMqloQ_Z\",\"type\":\"paragraph\",\"data\":{\"text\":\" method creates a new array by flattening nested arrays.\"}},{\"id\":\"rHITEck7zQ\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, [3, 4], [5, 6]];\\n\\nconst result = numbers.flat();\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"pviGGBe10n\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"XcKMHMyiBN\",\"type\":\"code\",\"data\":{\"code\":\"[1, 2, 3, 4, 5, 6]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"zKmA0WhVVs\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can specify the depth:\"}},{\"id\":\"Z7C7arO5cZ\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, [2, [3, [4]]]];\\n\\nconsole.log(numbers.flat(2));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"GfI-j3drbP\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Mo7yXA7eYJ\",\"type\":\"code\",\"data\":{\"code\":\"[1, 2, 3, 4, [4]]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"EeHO4nvx9P\",\"type\":\"header\",\"data\":{\"text\":\"5.23 flatMap()\",\"level\":3}},{\"id\":\"xJX9wd86Fg\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"-U1zhLYMFW\",\"type\":\"code\",\"data\":{\"code\":\"flatMap()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"DfFiC3dhK0\",\"type\":\"paragraph\",\"data\":{\"text\":\" method maps every element and flattens the resulting array by one level.\"}},{\"id\":\"SC6XK5pl3T\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3];\\n\\nconst result = numbers.flatMap((number) =&gt; [number, number * 2]);\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"6ZJ5wKxdBU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"9uoZD9Io6e\",\"type\":\"code\",\"data\":{\"code\":\"[1, 2, 2, 4, 3, 6]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"PHDR18tmI0\",\"type\":\"header\",\"data\":{\"text\":\"5.24 fill()\",\"level\":3}},{\"id\":\"SqD0jeukCk\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"BO-2mO5Q6m\",\"type\":\"code\",\"data\":{\"code\":\"fill()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"mOjIWOuG5Y\",\"type\":\"paragraph\",\"data\":{\"text\":\" method fills array elements with a specified value.\"}},{\"id\":\"34i1C5U9SP\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4, 5];\\n\\nnumbers.fill(0, 1, 4);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"WN50nd6uqK\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"lEmsUWUBBe\",\"type\":\"code\",\"data\":{\"code\":\"[1, 0, 0, 0, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"6Hsqp9b00W\",\"type\":\"paragraph\",\"data\":{\"text\":\"The original array is modified.\"}},{\"id\":\"VNVVWt5s2f\",\"type\":\"header\",\"data\":{\"text\":\"5.25 copyWithin()\",\"level\":3}},{\"id\":\"fh2_3y6WhU\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"DWiJe6wA6T\",\"type\":\"code\",\"data\":{\"code\":\"copyWithin()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"9GLS6dK7ap\",\"type\":\"paragraph\",\"data\":{\"text\":\" method copies a portion of an array to another position in the same array.\"}},{\"id\":\"fJZlnzFeQQ\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4, 5];\\n\\nnumbers.copyWithin(0, 3);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"F0es3hOBOV\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"lCNeFJsp9l\",\"type\":\"code\",\"data\":{\"code\":\"[4, 5, 3, 4, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"DfdwQfdzq5\",\"type\":\"paragraph\",\"data\":{\"text\":\"This method modifies the original array.\"}},{\"id\":\"01cDZbbOOh\",\"type\":\"header\",\"data\":{\"text\":\"6. Modern JavaScript Array Methods\",\"level\":2}},{\"id\":\"IXEzC2nz0v\",\"type\":\"paragraph\",\"data\":{\"text\":\"Modern JavaScript includes methods that make array operations safer and more convenient.\"}},{\"id\":\"bVqjGW9dp1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unlike some older methods, these methods return new arrays instead of modifying the original array.\"}},{\"id\":\"SWq1LyY_86\",\"type\":\"header\",\"data\":{\"text\":\"6.1 toSorted()\",\"level\":3}},{\"id\":\"GiCmO7jCl5\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"glGWijPtT_\",\"type\":\"code\",\"data\":{\"code\":\"toSorted()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"bvZNlRAa3l\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a new sorted array without changing the original.\"}},{\"id\":\"0RL3X1HpPf\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [30, 10, 50, 20];\\n\\nconst sortedNumbers = numbers.toSorted((a, b) =&gt; a - b);\\n\\nconsole.log(sortedNumbers);\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"mWapDrWvXW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"dTcg46rmni\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30, 50]\\n[30, 10, 50, 20]\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"OB7WvpyjQR\",\"type\":\"header\",\"data\":{\"text\":\"6.2 toReversed()\",\"level\":3}},{\"id\":\"ruFLnKvi-i\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"z-mOmzS4ab\",\"type\":\"code\",\"data\":{\"code\":\"toReversed()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"oobWPpHIVr\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a new array with the elements in reverse order.\"}},{\"id\":\"TuNlByDnmt\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4];\\n\\nconst reversed = numbers.toReversed();\\n\\nconsole.log(reversed);\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"mpb-cg0eAW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"s6W7Pe7uu7\",\"type\":\"code\",\"data\":{\"code\":\"[4, 3, 2, 1]\\n[1, 2, 3, 4]\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"U7gkTsswM3\",\"type\":\"header\",\"data\":{\"text\":\"6.3 toSpliced()\",\"level\":3}},{\"id\":\"wBDcz0su9H\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"jxewskdFuc\",\"type\":\"code\",\"data\":{\"code\":\"toSpliced()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"nqAdWCxJXS\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a new array with elements added, removed, or replaced without changing the original array.\"}},{\"id\":\"hVlsTVOxXt\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nconst updatedFruits = fruits.toSpliced(1, 1, \\\"Orange\\\");\\n\\nconsole.log(updatedFruits);\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"l5uGpey7fS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"_oWJxpkk0c\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Orange\\\", \\\"Mango\\\"]\\n[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"css\",\"raw\":true}},{\"id\":\"1iC8K6A8_M\",\"type\":\"header\",\"data\":{\"text\":\"6.4 with()\",\"level\":3}},{\"id\":\"xmIaEhB0AM\",\"type\":\"paragraph\",\"data\":{\"text\":\"The \"}},{\"id\":\"FPiMYgQ4SJ\",\"type\":\"code\",\"data\":{\"code\":\"with()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"69H6t_fMNt\",\"type\":\"paragraph\",\"data\":{\"text\":\" method returns a new array with an element replaced at a specified index.\"}},{\"id\":\"WhJ_49b8Zi\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nconst updatedFruits = fruits.with(1, \\\"Orange\\\");\\n\\nconsole.log(updatedFruits);\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"NH3Tx3oZuG\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"x7LbhYXTpI\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Orange\\\", \\\"Mango\\\"]\\n[\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"]\",\"language\":\"css\",\"raw\":true}},{\"id\":\"5nMI-7pSYb\",\"type\":\"paragraph\",\"data\":{\"text\":\"These newer methods are useful when you want to avoid modifying existing data, especially when working with React state.\"}},{\"id\":\"XWKxDwAgH4\",\"type\":\"header\",\"data\":{\"text\":\"7. Static Array Methods\",\"level\":2}},{\"id\":\"MKZbjlUTMm\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript also provides static methods on the \"}},{\"id\":\"UG8Sr9YY6x\",\"type\":\"code\",\"data\":{\"code\":\"Array\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"YBUrkom6Vb\",\"type\":\"paragraph\",\"data\":{\"text\":\" object.\"}},{\"id\":\"RENFs8qz-6\",\"type\":\"header\",\"data\":{\"text\":\"7.1 Array.isArray()\",\"level\":3}},{\"id\":\"plys3vF91-\",\"type\":\"paragraph\",\"data\":{\"text\":\"Checks whether a value is an array.\"}},{\"id\":\"fZzHZ4okSp\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\"];\\nconst name = \\\"Sam\\\";\\n\\nconsole.log(Array.isArray(fruits));\\nconsole.log(Array.isArray(name));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"Lyhedq-d4y\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"EaIfd_2sI9\",\"type\":\"code\",\"data\":{\"code\":\"true\\nfalse\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"BFO3T8kC2B\",\"type\":\"header\",\"data\":{\"text\":\"7.2 Array.from()\",\"level\":3}},{\"id\":\"b89jSfq-IM\",\"type\":\"paragraph\",\"data\":{\"text\":\"Creates an array from an iterable or array-like object.\"}},{\"id\":\"G9HpoLUGjv\",\"type\":\"code\",\"data\":{\"code\":\"const name = \\\"Sam\\\";\\n\\nconst characters = Array.from(name);\\n\\nconsole.log(characters);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"LvP_mzqEuS\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"rs1fpK-0YL\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"S\\\", \\\"a\\\", \\\"m\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"8Pe1gIQ_7U\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can also use a mapping function:\"}},{\"id\":\"wOa-kV67j3\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = Array.from([1, 2, 3], (number) =&gt; number * 2);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"cDpeKWwrSq\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"TPS22pjXpR\",\"type\":\"code\",\"data\":{\"code\":\"[2, 4, 6]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"ohxMqBHkgh\",\"type\":\"header\",\"data\":{\"text\":\"7.3 Array.of()\",\"level\":3}},{\"id\":\"Snp9H_qmZR\",\"type\":\"paragraph\",\"data\":{\"text\":\"Creates an array from the arguments passed to it.\"}},{\"id\":\"-Hey6ie9Qz\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = Array.of(10, 20, 30);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"RSygG37dwW\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"zfb-H3ZI4F\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"vO4Dm2YBG6\",\"type\":\"header\",\"data\":{\"text\":\"8. JavaScript Array Methods: map() vs filter() vs reduce()\",\"level\":2}},{\"id\":\"_sH7RT8xqP\",\"type\":\"paragraph\",\"data\":{\"text\":\"These three methods are especially important in JavaScript development and technical interviews.\"}},{\"id\":\"ElxQuK8wLl\",\"type\":\"paragraph\",\"data\":{\"text\":\"MethodPurposeReturn valuemap()Transform every elementNew arrayfilter()Select matching elementsNew arrayreduce()Combine elements into a resultAccumulated value\"}},{\"id\":\"rQKP8FtXoA\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's understand them using one example.\"}},{\"id\":\"S5tnpXdy_N\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40, 50];\\n\\n\/\/ Transform elements\\nconst doubled = numbers.map((number) =&gt; number * 2);\\n\\n\/\/ Select matching elements\\nconst filtered = numbers.filter((number) =&gt; number &gt; 25);\\n\\n\/\/ Calculate total\\nconst total = numbers.reduce((sum, number) =&gt; sum + number, 0);\\n\\nconsole.log(doubled);\\nconsole.log(filtered);\\nconsole.log(total);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"2JQNn7h4iw\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"SoV6rOo0Xr\",\"type\":\"code\",\"data\":{\"code\":\"[20, 40, 60, 80, 100]\\n[30, 40, 50]\\n150\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"CffmpBMUn2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"386DipOfU3\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"RvD-8gzwLs\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you want to transform data, \"}},{\"id\":\"8vbHtXz2zT\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"EY_jSe8zyL\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you want to select data, and \"}},{\"id\":\"dFlqMZSg1U\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"rNRrFwG_-x\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you want to calculate or accumulate a result.\"}},{\"id\":\"8QPhH3oHuR\",\"type\":\"header\",\"data\":{\"text\":\"9. Real-World JavaScript Array Examples\",\"level\":2}},{\"id\":\"sv0-4zkLId\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now let's apply array methods to practical problems you may encounter while developing websites and applications.\"}},{\"id\":\"uqPwb4rJI_\",\"type\":\"header\",\"data\":{\"text\":\"Example 1: Display Products Using map()\",\"level\":3}},{\"id\":\"ZN-HMzawl5\",\"type\":\"paragraph\",\"data\":{\"text\":\"Imagine you are building an e-commerce website and need to display products.\"}},{\"id\":\"P2L-QgrrZA\",\"type\":\"code\",\"data\":{\"code\":\"const products = [\\n    { id: 1, name: \\\"Laptop\\\", price: 50000 },\\n    { id: 2, name: \\\"Mouse\\\", price: 500 },\\n    { id: 3, name: \\\"Keyboard\\\", price: 1500 }\\n];\\n\\nconst productNames = products.map((product) =&gt; product.name);\\n\\nconsole.log(productNames);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"ZgOqf9Lacq\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"IPYlGyxeZu\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Laptop\\\", \\\"Mouse\\\", \\\"Keyboard\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"X2H4bq2GOW\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is useful when rendering product lists in React.\"}},{\"id\":\"DCTAxPMAme\",\"type\":\"header\",\"data\":{\"text\":\"Example 2: Filter Products by Price\",\"level\":3}},{\"id\":\"7SUZfQsRd7\",\"type\":\"paragraph\",\"data\":{\"text\":\"Suppose you want to display products that cost less than \u20b92,000.\"}},{\"id\":\"_jTGZQPXEx\",\"type\":\"code\",\"data\":{\"code\":\"const products = [\\n    { name: \\\"Laptop\\\", price: 50000 },\\n    { name: \\\"Mouse\\\", price: 500 },\\n    { name: \\\"Keyboard\\\", price: 1500 },\\n    { name: \\\"Monitor\\\", price: 12000 }\\n];\\n\\nconst affordableProducts = products.filter((product) =&gt; {\\n    return product.price &lt; 2000;\\n});\\n\\nconsole.log(affordableProducts);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"6AqL01sCJX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"VEuCHTYXab\",\"type\":\"code\",\"data\":{\"code\":\"[\\n    { name: \\\"Mouse\\\", price: 500 },\\n    { name: \\\"Keyboard\\\", price: 1500 }\\n]\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"WSqmxL7FrC\",\"type\":\"header\",\"data\":{\"text\":\"Example 3: Calculate Shopping Cart Total\",\"level\":3}},{\"id\":\"6y65B-TqDK\",\"type\":\"paragraph\",\"data\":{\"text\":\"A shopping cart contains multiple products. You need to calculate the total amount.\"}},{\"id\":\"Yx38VbxR7o\",\"type\":\"code\",\"data\":{\"code\":\"const cart = [\\n    { name: \\\"Laptop\\\", price: 50000, quantity: 1 },\\n    { name: \\\"Mouse\\\", price: 500, quantity: 2 },\\n    { name: \\\"Keyboard\\\", price: 1500, quantity: 1 }\\n];\\n\\nconst total = cart.reduce((sum, product) =&gt; {\\n    return sum + product.price * product.quantity;\\n}, 0);\\n\\nconsole.log(total);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"9WaYVm32w2\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Yn3e9XFZjn\",\"type\":\"code\",\"data\":{\"code\":\"52500\",\"language\":\"\",\"raw\":true}},{\"id\":\"muPVr3ke8s\",\"type\":\"header\",\"data\":{\"text\":\"Example 4: Find a User by ID\",\"level\":3}},{\"id\":\"mmrLS2wvJq\",\"type\":\"code\",\"data\":{\"code\":\"const users = [\\n    { id: 101, name: \\\"Aman\\\" },\\n    { id: 102, name: \\\"Rahul\\\" },\\n    { id: 103, name: \\\"Priya\\\" }\\n];\\n\\nconst user = users.find((user) =&gt; user.id === 102);\\n\\nconsole.log(user);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"-XN1WQ6jOU\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"g76xphbO5W\",\"type\":\"code\",\"data\":{\"code\":\"{ id: 102, name: \\\"Rahul\\\" }\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"xko9Uhc-2f\",\"type\":\"header\",\"data\":{\"text\":\"Example 5: Remove Duplicate Values\",\"level\":3}},{\"id\":\"RFuNsVh3cG\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can use \"}},{\"id\":\"poJwPbLaSX\",\"type\":\"code\",\"data\":{\"code\":\"Set\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"K5zr-0hMKB\",\"type\":\"paragraph\",\"data\":{\"text\":\" with the spread operator to remove duplicate primitive values.\"}},{\"id\":\"ox1GzWZwRf\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 10, 30, 20, 40];\\n\\nconst uniqueNumbers = [...new Set(numbers)];\\n\\nconsole.log(uniqueNumbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"d2o5ga0j2K\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"V5qq5GjNXq\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30, 40]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"0O7nMyNLKM\",\"type\":\"header\",\"data\":{\"text\":\"Example 6: Count Occurrences of Elements\",\"level\":3}},{\"id\":\"sAwrNypBaY\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can use \"}},{\"id\":\"04LK4Bpz9B\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"U8-x5Sfe6X\",\"type\":\"paragraph\",\"data\":{\"text\":\" to count how many times each value appears.\"}},{\"id\":\"BuNOUFrqqx\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Apple\\\", \\\"Mango\\\", \\\"Banana\\\", \\\"Apple\\\"];\\n\\nconst result = fruits.reduce((count, fruit) =&gt; {\\n    count[fruit] = (count[fruit] || 0) + 1;\\n    return count;\\n}, {});\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"PvlRJ3W6IX\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"RHlrQQoi-b\",\"type\":\"code\",\"data\":{\"code\":\"{\\n    Apple: 3,\\n    Banana: 2,\\n    Mango: 1\\n}\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"QpLvMjua_P\",\"type\":\"header\",\"data\":{\"text\":\"10. How to Loop Through JavaScript Arrays\",\"level\":2}},{\"id\":\"1bQEFkNgfM\",\"type\":\"paragraph\",\"data\":{\"text\":\"There are multiple ways to iterate over array elements.\"}},{\"id\":\"1jGyhZUK0R\",\"type\":\"header\",\"data\":{\"text\":\"Using a for Loop\",\"level\":3}},{\"id\":\"AVnNDTDcqJ\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfor (let i = 0; i &lt; fruits.length; i++) {\\n    console.log(fruits[i]);\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"LXOGQshCqz\",\"type\":\"header\",\"data\":{\"text\":\"Using for...of\",\"level\":3}},{\"id\":\"Mc8AN5JMrJ\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfor (const fruit of fruits) {\\n    console.log(fruit);\\n}\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"k6OA8K6qTE\",\"type\":\"header\",\"data\":{\"text\":\"Using forEach()\",\"level\":3}},{\"id\":\"QWZvCuwc0r\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits.forEach((fruit) =&gt; {\\n    console.log(fruit);\\n});\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"_M3FJzsXOm\",\"type\":\"paragraph\",\"data\":{\"text\":\"All three approaches can iterate over an array, but they have different use cases.\"}},{\"id\":\"2b_8Hjca8G\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use a traditional \"}},{\"id\":\"tKaKPCLx8k\",\"type\":\"code\",\"data\":{\"code\":\"for\",\"language\":\"\",\"raw\":true}},{\"id\":\"BnqBUr4bE6\",\"type\":\"paragraph\",\"data\":{\"text\":\" loop when you need index control or want to use \"}},{\"id\":\"eg6jByCWfZ\",\"type\":\"code\",\"data\":{\"code\":\"break\",\"language\":\"kotlin\",\"raw\":true}},{\"id\":\"LztnjFRdat\",\"type\":\"paragraph\",\"data\":{\"text\":\" and \"}},{\"id\":\"HXBCC4wsQ7\",\"type\":\"code\",\"data\":{\"code\":\"continue\",\"language\":\"kotlin\",\"raw\":true}},{\"id\":\"piRCReD352\",\"type\":\"paragraph\",\"data\":{\"text\":\". Use \"}},{\"id\":\"4s6_RpP4UD\",\"type\":\"code\",\"data\":{\"code\":\"for...of\",\"language\":\"\",\"raw\":true}},{\"id\":\"kW4pCewfSR\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you want to iterate over values. Use \"}},{\"id\":\"nsanrcNO6F\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"EzrdQhM-2B\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you want to execute a callback for each element.\"}},{\"id\":\"4oGyhUlMsh\",\"type\":\"header\",\"data\":{\"text\":\"11. Mutable vs Immutable Array Methods\",\"level\":2}},{\"id\":\"E8e0ucYMlC\",\"type\":\"paragraph\",\"data\":{\"text\":\"One important concept in JavaScript is understanding whether an array method modifies the original array.\"}},{\"id\":\"_18VDoOqNE\",\"type\":\"header\",\"data\":{\"text\":\"Methods That Modify the Original Array\",\"level\":3}},{\"id\":\"hzv-Y63pjS\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"push()\",\"pop()\",\"shift()\",\"unshift()\",\"splice()\",\"sort()\",\"reverse()\",\"fill()\",\"copyWithin()\"]}},{\"id\":\"6kauFucSMD\",\"type\":\"header\",\"data\":{\"text\":\"Methods That Return a New Array or Value Without Modifying the Original\",\"level\":3}},{\"id\":\"3Ln9IOGTai\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"map()\",\"filter()\",\"slice()\",\"concat()\",\"flat()\",\"flatMap()\",\"toSorted()\",\"toReversed()\",\"toSpliced()\",\"with()\"]}},{\"id\":\"RuxrEwfQfH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Methods such as \"}},{\"id\":\"56__QdCBjy\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"wHdkKoQaXX\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"YBopcznG21\",\"type\":\"code\",\"data\":{\"code\":\"includes()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"o9aTXnd83z\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"22ckofsaHU\",\"type\":\"code\",\"data\":{\"code\":\"indexOf()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"dcPFzasJOx\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"K1u7dfKCtR\",\"type\":\"code\",\"data\":{\"code\":\"some()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"UqvwSUTxlk\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"ZKOU-2e90C\",\"type\":\"code\",\"data\":{\"code\":\"every()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"CJO44EXvnz\",\"type\":\"paragraph\",\"data\":{\"text\":\" return values without modifying the original array.\"}},{\"id\":\"oM9bxB7wgC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Why does this matter?\"}},{\"id\":\"GCuLrtd2yt\",\"type\":\"paragraph\",\"data\":{\"text\":\"When working with React, directly modifying state arrays can lead to unexpected UI behavior. Prefer creating a new array when updating state.\"}},{\"id\":\"kgDGw-cDo-\",\"type\":\"paragraph\",\"data\":{\"text\":\"For example:\"}},{\"id\":\"Fp6mD3qUsE\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30];\\n\\n\/\/ Avoid directly modifying existing state data\\n\/\/ numbers.push(40);\\n\\n\/\/ Create a new array instead\\nconst updatedNumbers = [...numbers, 40];\\n\\nconsole.log(updatedNumbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"mkfPYPdNxb\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Zv9eQg-wA3\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30, 40]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"usNm05uWpT\",\"type\":\"header\",\"data\":{\"text\":\"12. Common Mistakes When Using JavaScript Array Methods\",\"level\":2}},{\"id\":\"xBAPsS2PU9\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 1: Forgetting That sort() Uses String Ordering by Default\",\"level\":3}},{\"id\":\"hEw0wi2yzN\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 100, 20, 5];\\n\\nnumbers.sort();\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"CjAkpcnFCe\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"Y5rPvIM0XV\",\"type\":\"code\",\"data\":{\"code\":\"[1, 100, 20, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"DHDsbDsaif\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use a numeric comparator:\"}},{\"id\":\"RcfOQ-ot7G\",\"type\":\"code\",\"data\":{\"code\":\"numbers.sort((a, b) =&gt; a - b);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"hmBw2JsM-8\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 2: Expecting forEach() to Return a New Array\",\"level\":3}},{\"id\":\"o6Psj1GrfB\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3];\\n\\nconst result = numbers.forEach((number) =&gt; number * 2);\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"8iGPtxQ1NJ\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"oONCTrz3nb\",\"type\":\"code\",\"data\":{\"code\":\"undefined\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"AOxAICpoSu\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"KVOm1QdvQ9\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"vqAfOoiWWX\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you need a transformed array.\"}},{\"id\":\"0EIhcYblsS\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 3: Confusing find() and filter()\",\"level\":3}},{\"id\":\"MUYoylmoV8\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 20, 30, 40];\\n\\nconst result = numbers.find((number) =&gt; number &gt; 15);\\n\\nconsole.log(result);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"tkkujkvJGI\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"8_1L6u780L\",\"type\":\"code\",\"data\":{\"code\":\"20\",\"language\":\"\",\"raw\":true}},{\"id\":\"_i_aZLfsXV\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"EAk58zbHDE\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns only the first matching element. Use \"}},{\"id\":\"-aZutruEdj\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"wUnIbTk1G8\",\"type\":\"paragraph\",\"data\":{\"text\":\" to get every matching element.\"}},{\"id\":\"kZUu-n9OBx\",\"type\":\"header\",\"data\":{\"text\":\"Mistake 4: Forgetting That splice() Changes the Original Array\",\"level\":3}},{\"id\":\"zhnsb6BjY5\",\"type\":\"code\",\"data\":{\"code\":\"const fruits = [\\\"Apple\\\", \\\"Banana\\\", \\\"Mango\\\"];\\n\\nfruits.splice(1, 1);\\n\\nconsole.log(fruits);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"fcP_V96mHf\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"UR2yuxYgq2\",\"type\":\"code\",\"data\":{\"code\":\"[\\\"Apple\\\", \\\"Mango\\\"]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"9EXPAzLd2n\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you need a non-mutating alternative, consider \"}},{\"id\":\"cA3CSGMRdk\",\"type\":\"code\",\"data\":{\"code\":\"toSpliced()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"x0X7w4IaMU\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"DASlNkTlUw\",\"type\":\"header\",\"data\":{\"text\":\"13. JavaScript Array Practice Exercises\",\"level\":2}},{\"id\":\"1Jsf6FUEE8\",\"type\":\"paragraph\",\"data\":{\"text\":\"Practice is one of the best ways to understand JavaScript array methods.\"}},{\"id\":\"JN9butCFvm\",\"type\":\"paragraph\",\"data\":{\"text\":\"Try solving these exercises before checking the solutions.\"}},{\"id\":\"3OlmfRKdHJ\",\"type\":\"header\",\"data\":{\"text\":\"Exercise 1: Find Even Numbers\",\"level\":3}},{\"id\":\"avqYSXkDVE\",\"type\":\"paragraph\",\"data\":{\"text\":\"Given an array of numbers, return only the even numbers.\"}},{\"id\":\"TLRRE8UJ7H\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [10, 15, 20, 25, 30, 35];\\n\\n\/\/ Write your solution here\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"2mGHkO6us1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expected output:\"}},{\"id\":\"q-pkC6T6kD\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 30]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"cYaFEfi4sC\",\"type\":\"header\",\"data\":{\"text\":\"Exercise 2: Double Every Number\",\"level\":3}},{\"id\":\"EqOf6mYJqv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"nB9Wz5Fv8X\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Xcvj7myOMr\",\"type\":\"paragraph\",\"data\":{\"text\":\" to double every number.\"}},{\"id\":\"kzY3Q_7nKE\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4, 5];\\n\\n\/\/ Write your solution here\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"WIJUVamqQg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expected output:\"}},{\"id\":\"k0ECsM69Ex\",\"type\":\"code\",\"data\":{\"code\":\"[2, 4, 6, 8, 10]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"rslzh2wn5b\",\"type\":\"header\",\"data\":{\"text\":\"Exercise 3: Calculate the Total\",\"level\":3}},{\"id\":\"JaMAJ-Fkp8\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"pj91tma9_N\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"LTcmGQTXPY\",\"type\":\"paragraph\",\"data\":{\"text\":\" to calculate the sum of all numbers.\"}},{\"id\":\"S7yltnk805\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [100, 200, 300, 400];\\n\\n\/\/ Write your solution here\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"DxlZn3ZezV\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expected output:\"}},{\"id\":\"bQbR_69ASa\",\"type\":\"code\",\"data\":{\"code\":\"1000\",\"language\":\"yaml\",\"raw\":true}},{\"id\":\"YnIBj5OCR8\",\"type\":\"header\",\"data\":{\"text\":\"Exercise 4: Find the Highest Number\",\"level\":3}},{\"id\":\"ysqwGHvXL1\",\"type\":\"paragraph\",\"data\":{\"text\":\"Find the highest number in an array.\"}},{\"id\":\"oPhCj5AKUA\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [15, 90, 25, 120, 45];\\n\\n\/\/ Write your solution here\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"WWktJaIheb\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expected output:\"}},{\"id\":\"W8_OpKwk0D\",\"type\":\"code\",\"data\":{\"code\":\"120\",\"language\":\"\",\"raw\":true}},{\"id\":\"nO4_1YXU8n\",\"type\":\"header\",\"data\":{\"text\":\"Exercise 5: Remove Duplicate Values\",\"level\":3}},{\"id\":\"JPwxV8cW5j\",\"type\":\"paragraph\",\"data\":{\"text\":\"Remove duplicate numbers from the array.\"}},{\"id\":\"Et1Q4dEg2S\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 2, 3, 4, 4, 5];\\n\\n\/\/ Write your solution here\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"XSEQta4mdg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Expected output:\"}},{\"id\":\"fgypLOyWSr\",\"type\":\"code\",\"data\":{\"code\":\"[1, 2, 3, 4, 5]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"HcV4U8tloJ\",\"type\":\"header\",\"data\":{\"text\":\"14. JavaScript Array Interview Questions\",\"level\":2}},{\"id\":\"o8_P7Ttv2l\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q1. What is an array in JavaScript?\"}},{\"id\":\"rrgSBVJinE\",\"type\":\"paragraph\",\"data\":{\"text\":\"An array is an ordered collection of values stored in a single variable. It can contain multiple data types and uses zero-based indexing.\"}},{\"id\":\"AYFDUUJ_p3\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q2. What is the difference between push() and pop()?\"}},{\"id\":\"8fQOyNUn0b\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5J1OWQFhQk\",\"type\":\"paragraph\",\"data\":{\"text\":\" adds elements to the end of an array, whereas \"}},{\"id\":\"qcvgF50Ouo\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"9DMgJyMa5d\",\"type\":\"paragraph\",\"data\":{\"text\":\" removes the last element.\"}},{\"id\":\"Nrg2zluxjz\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q3. What is the difference between shift() and unshift()?\"}},{\"id\":\"fm3KrsAtcw\",\"type\":\"code\",\"data\":{\"code\":\"shift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"x4kSlBkkRv\",\"type\":\"paragraph\",\"data\":{\"text\":\" removes the first element, whereas \"}},{\"id\":\"-8A24rYqXn\",\"type\":\"code\",\"data\":{\"code\":\"unshift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"LR0eUfsCy0\",\"type\":\"paragraph\",\"data\":{\"text\":\" adds elements to the beginning.\"}},{\"id\":\"XxDXMkyltr\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q4. What is the difference between map() and forEach()?\"}},{\"id\":\"8OdLdgJF2f\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"kuGv0CwSAS\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns a new array containing transformed elements. \"}},{\"id\":\"f6W0zU3XnN\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"2BQWW2bOXg\",\"type\":\"paragraph\",\"data\":{\"text\":\" executes a callback for each element and returns \"}},{\"id\":\"-7azj0f0jB\",\"type\":\"code\",\"data\":{\"code\":\"undefined\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"spmtJIZRl4\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"2sOdUn5V4y\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q5. What is the difference between find() and filter()?\"}},{\"id\":\"7PABq-tPiV\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"S8G_OtsVxG\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns the first matching element. \"}},{\"id\":\"P5emOYMMv4\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"fhun0hr7FZ\",\"type\":\"paragraph\",\"data\":{\"text\":\" returns a new array containing all matching elements.\"}},{\"id\":\"ca2sAifSl0\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q6. What is the difference between slice() and splice()?\"}},{\"id\":\"FpExC3_lfm\",\"type\":\"code\",\"data\":{\"code\":\"slice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"pD5mwXsimI\",\"type\":\"paragraph\",\"data\":{\"text\":\" extracts elements without modifying the original array. \"}},{\"id\":\"jZq9TZ6mkH\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"brkBaTLu7G\",\"type\":\"paragraph\",\"data\":{\"text\":\" adds, removes, or replaces elements and modifies the original array.\"}},{\"id\":\"SSWw6xipqp\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q7. How do you check whether a variable is an array?\"}},{\"id\":\"DH7zglZN0Y\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"n90_WJQU0p\",\"type\":\"code\",\"data\":{\"code\":\"Array.isArray()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"aUDxqheBKY\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"XooBV3V4RF\",\"type\":\"code\",\"data\":{\"code\":\"const data = [10, 20, 30];\\n\\nconsole.log(Array.isArray(data));\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"2NKck4jLKH\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"abQDkWAgpl\",\"type\":\"code\",\"data\":{\"code\":\"true\",\"language\":\"bash\",\"raw\":true}},{\"id\":\"qJXGk-eNCT\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q8. Does sort() work correctly with numbers by default?\"}},{\"id\":\"B9UcXDEWKM\",\"type\":\"paragraph\",\"data\":{\"text\":\"No. The default sorting behavior compares elements as strings. Use a numeric comparator for correct numeric sorting.\"}},{\"id\":\"IAs_3Og4US\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q9. What does reduce() do?\"}},{\"id\":\"VIK3nVo-Fw\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Cs8hipZiR6\",\"type\":\"paragraph\",\"data\":{\"text\":\" executes a callback over array elements and accumulates them into a single result, such as a number, object, or another data structure.\"}},{\"id\":\"OFOVE8RKNl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Q10. Which array methods modify the original array?\"}},{\"id\":\"10aFkdzifd\",\"type\":\"paragraph\",\"data\":{\"text\":\"Examples include \"}},{\"id\":\"Ftc1Ap5vAN\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"tq3sJwf5vG\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"GuxQLctcfb\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"2l_OaFAGvu\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"MGuG6fbZ5d\",\"type\":\"code\",\"data\":{\"code\":\"shift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Zku9thpcAi\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"rTbA5UEARv\",\"type\":\"code\",\"data\":{\"code\":\"unshift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"OYTKKIiQVQ\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"QGGeYiUfWw\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"wBEzf-RBsq\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"YRQYiQ0GNP\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"mZW_Gp8O_E\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"llBU5BUVlR\",\"type\":\"code\",\"data\":{\"code\":\"reverse()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"lIFPTHOrfW\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"bIRm5OJWyM\",\"type\":\"header\",\"data\":{\"text\":\"15. JavaScript Array Methods Quick Reference\",\"level\":2}},{\"id\":\"wX8NyDcLie\",\"type\":\"paragraph\",\"data\":{\"text\":\"MethodPurposeModifies original?push()Add at the endYespop()Remove from the endYesshift()Remove from the beginningYesunshift()Add at the beginningYessplice()Add, remove, or replaceYesslice()Extract a portionNoconcat()Combine arraysNojoin()Convert to a stringNoreverse()Reverse elementsYessort()Sort elementsYesmap()Transform elementsNofilter()Select matching elementsNoreduce()Accumulate a resultNoforEach()Execute a callbackNofind()Find the first matchNofindIndex()Find the first matching indexNoincludes()Check for a valueNoindexOf()Find the first indexNolastIndexOf()Find the last indexNosome()Check whether any matchNoevery()Check whether all matchNoflat()Flatten nested arraysNoflatMap()Map and flatten one levelNofill()Fill with a valueYescopyWithin()Copy within the arrayYestoSorted()Return sorted copyNotoReversed()Return reversed copyNotoSpliced()Return spliced copyNowith()Return copy with replacementNo\"}},{\"id\":\"eoSk3LEBb4\",\"type\":\"header\",\"data\":{\"text\":\"Conclusion\",\"level\":2}},{\"id\":\"s7hp2vOd5S\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript arrays are essential for handling collections of data in modern web applications. Understanding array methods makes it easier to write clean, readable, and efficient JavaScript code.\"}},{\"id\":\"KsgszfnSbD\",\"type\":\"paragraph\",\"data\":{\"text\":\"Start by mastering commonly used methods such as \"}},{\"id\":\"OcQvhkSzAl\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"wEjXp2LLcy\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"Cy0KYHUYQC\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"aUakpfZ7ik\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"6GU0iFLThz\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"H1hQ2UaM3d\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"WCb12iEaxF\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"sbT3XHVdao\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"l8kn1VPQt-\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"8nIwUIF4yy\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"DFpfpu66IG\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"cprWUWYHCQ\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"4t08FiwVyh\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"pT9u2b7Vky\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"kmXgztcBl7\",\"type\":\"code\",\"data\":{\"code\":\"slice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"pzVktX4Lwp\",\"type\":\"paragraph\",\"data\":{\"text\":\". Then practice using them in real-world projects such as shopping carts, product listings, dashboards, and user management systems.\"}},{\"id\":\"TCgdzU1j8m\",\"type\":\"paragraph\",\"data\":{\"text\":\"Do not just memorize these methods. Understand what each method returns, whether it modifies the original array, and when to use it.\"}},{\"id\":\"aJ-V9QP8Xl\",\"type\":\"paragraph\",\"data\":{\"text\":\"Keep practicing, build small projects, and gradually combine multiple array methods to solve real programming problems.\"}},{\"id\":\"8660cL-01I\",\"type\":\"paragraph\",\"data\":{\"text\":\"Happy Coding!\"}},{\"id\":\"rZdYzAc9zi\",\"type\":\"header\",\"data\":{\"text\":\"Frequently Asked Questions\",\"level\":2}},{\"id\":\"3hLmcM_B9_\",\"type\":\"header\",\"data\":{\"text\":\"1. What are the most commonly used JavaScript array methods?\",\"level\":3}},{\"id\":\"sHS_YHoDyC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Some of the most commonly used methods are \"}},{\"id\":\"HXhFv_fPkz\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"zozZYE3MKf\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"RUy1SFSUCX\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"u07FJUgtV1\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"RsB1H9qnhJ\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"cuqPNhxHCv\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"7O_KoVk86v\",\"type\":\"code\",\"data\":{\"code\":\"find()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"q3mpbTvzdX\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"k02aDwMBi1\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5B6RjwPqOf\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"3MaeAGm4Ja\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"0kW58rPhTZ\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"explf704WG\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"OsVWz05R5l\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"LzAHA-QiEj\",\"type\":\"code\",\"data\":{\"code\":\"slice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"bkIhSNLFHg\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"yBBpLLAOEd\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"w6Vw6wpEqj\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"XeopxMx3tc\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"a7zQ6bUqks\",\"type\":\"paragraph\",\"data\":{\"text\":\".\"}},{\"id\":\"M0D61Iirzz\",\"type\":\"header\",\"data\":{\"text\":\"2. Which JavaScript array method is used to add elements?\",\"level\":3}},{\"id\":\"9i_WWf-N-D\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"xfT5UswI6Q\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"WWB9dmCaAh\",\"type\":\"paragraph\",\"data\":{\"text\":\" to add elements at the end and \"}},{\"id\":\"MvE7i_vjl9\",\"type\":\"code\",\"data\":{\"code\":\"unshift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"0Bumrp2H0c\",\"type\":\"paragraph\",\"data\":{\"text\":\" to add elements at the beginning.\"}},{\"id\":\"PnagIpxCTY\",\"type\":\"header\",\"data\":{\"text\":\"3. Which JavaScript array method is used to remove elements?\",\"level\":3}},{\"id\":\"OyujbEFAp9\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"x3Wm7s0ZgN\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"v8adS59h-P\",\"type\":\"paragraph\",\"data\":{\"text\":\" to remove the last element, \"}},{\"id\":\"xTRDj0YQFn\",\"type\":\"code\",\"data\":{\"code\":\"shift()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"uamebsW6hR\",\"type\":\"paragraph\",\"data\":{\"text\":\" to remove the first element, and \"}},{\"id\":\"0FVKTKjCt5\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"97d_1Y7YNu\",\"type\":\"paragraph\",\"data\":{\"text\":\" to remove elements from a specific position.\"}},{\"id\":\"NbNAK0MNhU\",\"type\":\"header\",\"data\":{\"text\":\"4. Is map() better than forEach()?\",\"level\":3}},{\"id\":\"V67yiJQuXc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Neither is universally better. Use \"}},{\"id\":\"2QIl3aSF1d\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Zr8i4N27Er\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you need a new transformed array. Use \"}},{\"id\":\"FzPLVq_AWe\",\"type\":\"code\",\"data\":{\"code\":\"forEach()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"LSfJkugxLg\",\"type\":\"paragraph\",\"data\":{\"text\":\" when you simply want to perform an action for each element.\"}},{\"id\":\"MTqX2SZBtK\",\"type\":\"header\",\"data\":{\"text\":\"5. What is the difference between map(), filter(), and reduce()?\",\"level\":3}},{\"id\":\"cZWyg-XL7i\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"heMdEz_GwR\",\"type\":\"paragraph\",\"data\":{\"text\":\" transforms each element, \"}},{\"id\":\"PQWIn8wPOT\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"epgIbFSWMB\",\"type\":\"paragraph\",\"data\":{\"text\":\" selects elements based on a condition, and \"}},{\"id\":\"KadBshZZ05\",\"type\":\"code\",\"data\":{\"code\":\"reduce()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"Pw5x5nVOU1\",\"type\":\"paragraph\",\"data\":{\"text\":\" combines elements into an accumulated result.\"}},{\"id\":\"APhMqtvDKO\",\"type\":\"header\",\"data\":{\"text\":\"6. Do JavaScript array methods modify the original array?\",\"level\":3}},{\"id\":\"sF7i6yZZJ-\",\"type\":\"paragraph\",\"data\":{\"text\":\"Some methods, such as \"}},{\"id\":\"sooqSTA6Lr\",\"type\":\"code\",\"data\":{\"code\":\"push()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"K1sh8vlvgm\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"OW224qeDe5\",\"type\":\"code\",\"data\":{\"code\":\"pop()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"XaHialfcza\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"Ag_NNvYhHx\",\"type\":\"code\",\"data\":{\"code\":\"splice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"IW46R_6tdB\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"u7rxhMPTFL\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"x6WTAUQOEf\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"85NxCSuius\",\"type\":\"code\",\"data\":{\"code\":\"reverse()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"5LF3gZxTut\",\"type\":\"paragraph\",\"data\":{\"text\":\", modify the original array. Others, such as \"}},{\"id\":\"WJnsi9iRpw\",\"type\":\"code\",\"data\":{\"code\":\"map()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"gFtL3ybutc\",\"type\":\"paragraph\",\"data\":{\"text\":\", \"}},{\"id\":\"ahjjGSpM1D\",\"type\":\"code\",\"data\":{\"code\":\"filter()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"DABKQptRfW\",\"type\":\"paragraph\",\"data\":{\"text\":\", and \"}},{\"id\":\"crqvvwDk4-\",\"type\":\"code\",\"data\":{\"code\":\"slice()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"rOwOiP65ZY\",\"type\":\"paragraph\",\"data\":{\"text\":\", return new results without modifying it.\"}},{\"id\":\"_TxT0NdkkZ\",\"type\":\"header\",\"data\":{\"text\":\"7. How can I remove duplicates from a JavaScript array?\",\"level\":3}},{\"id\":\"f5qWN0ZXXq\",\"type\":\"paragraph\",\"data\":{\"text\":\"For arrays of primitive values, you can use \"}},{\"id\":\"kmyHnG8EBI\",\"type\":\"code\",\"data\":{\"code\":\"Set\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"vfdSHziZ3Q\",\"type\":\"paragraph\",\"data\":{\"text\":\":\"}},{\"id\":\"EG3pvyULiR\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 2, 3, 3, 4];\\n\\nconst uniqueNumbers = [...new Set(numbers)];\\n\\nconsole.log(uniqueNumbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"68D4thx3tv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"HfPG1WqdTz\",\"type\":\"code\",\"data\":{\"code\":\"[1, 2, 3, 4]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"h0HtWBeFxO\",\"type\":\"header\",\"data\":{\"text\":\"8. How do I sort numbers in JavaScript?\",\"level\":3}},{\"id\":\"PiCBwRI3Va\",\"type\":\"paragraph\",\"data\":{\"text\":\"Use \"}},{\"id\":\"8WS3HozZB1\",\"type\":\"code\",\"data\":{\"code\":\"sort()\",\"language\":\"scss\",\"raw\":true}},{\"id\":\"c9CaWDHT9f\",\"type\":\"paragraph\",\"data\":{\"text\":\" with a numeric comparison function:\"}},{\"id\":\"sj9fIGcCHi\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [50, 10, 100, 20];\\n\\nnumbers.sort((a, b) =&gt; a - b);\\n\\nconsole.log(numbers);\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"VhlBYBByP3\",\"type\":\"paragraph\",\"data\":{\"text\":\"Output:\"}},{\"id\":\"hMzH-WpCpq\",\"type\":\"code\",\"data\":{\"code\":\"[10, 20, 50, 100]\",\"language\":\"json\",\"raw\":true}},{\"id\":\"M1K0yTn6Oj\",\"type\":\"header\",\"data\":{\"text\":\"9. What is the difference between Array.from() and Array.of()?\",\"level\":3}},{\"id\":\"KDG407t6XU\",\"type\":\"code\",\"data\":{\"code\":\"Array.from()\",\"language\":\"csharp\",\"raw\":true}},{\"id\":\"I3xjLSEt5i\",\"type\":\"paragraph\",\"data\":{\"text\":\" creates an array from an iterable or array-like value. \"}},{\"id\":\"xc3FMcMLyU\",\"type\":\"code\",\"data\":{\"code\":\"Array.of()\",\"language\":\"javascript\",\"raw\":true}},{\"id\":\"vLQE7i5lwq\",\"type\":\"paragraph\",\"data\":{\"text\":\" creates an array from the arguments supplied to it.\"}},{\"id\":\"nf4xCp3mZB\",\"type\":\"header\",\"data\":{\"text\":\"10. Where can I practice JavaScript array methods?\",\"level\":3}},{\"id\":\"2EH5HyK6hS\",\"type\":\"paragraph\",\"data\":{\"text\":\"You can practice by solving problems involving filtering products, calculating shopping cart totals, sorting data, finding users, removing duplicates, and transforming API responses.\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/javascript-array-methods-1794718447.jfif","status":"published","excerpt":"Learn JavaScript arrays and all important array methods with practical examples. Understand map(), filter(), reduce(), find(), sort(), slice(), splice(), and more with code and outputs.","published_at":"2026-11-15T04:54:07.000000Z","tags":"[\"JavaScript\",\"JavaScript Arrays\",\"Array Methods\",\"JavaScript Tutorial\",\"Web Development\",\"Programming\"]","created_at":"2026-11-15T04:54:07.000000Z","updated_at":"2026-11-22T12:41:15.000000Z","views":11,"scheduled_at":null,"score":1794718469},{"id":14,"user_id":1,"category_id":3,"title":"Ace Your Next Interview: Mastering the JavaScript filter() Method (With Top Questions)","slug":"javascript-filter-method-interview-questions","content":"{\"time\":1786289096184,\"blocks\":[{\"id\":\"ItJEvkT4n5\",\"type\":\"header\",\"data\":{\"text\":\"Ace Your Next Interview: Mastering the JavaScript <code>filter()<\/code> Method\",\"level\":2}},{\"id\":\"VFuYOdCYdC\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let\u2019s be completely honest for a second: JavaScript interviews can be incredibly intimidating. You sit down (or log onto a Zoom call), share your screen, and suddenly your mind goes blank. The interviewer pastes a massive array of deeply nested user objects into the code editor and says, <i>\\\"Can you extract only the active users who have made a purchase in the last 30 days?\\\"<\/i>\"}},{\"id\":\"aMAqskOJKd\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you are a frontend developer, you already know that Array manipulation is the absolute bread and butter of JavaScript interviews. Interviewers love arrays, and more specifically, they love Higher-Order Functions like <code>map()<\/code>, <code>reduce()<\/code>, and <code>filter()<\/code>.\"}},{\"id\":\"HCb5qmpF2E\",\"type\":\"paragraph\",\"data\":{\"text\":\"Today, we are going to put a massive spotlight on the <code>filter()<\/code> method. We won't just look at the basic documentation; we are going to dissect it through the lens of a technical interview. We'll explore why interviewers love it, the common traps they set for you, and the exact coding questions you can expect to face\u2014ranging from beginner-friendly warm-ups to senior-level architectural questions.\"}},{\"id\":\"sfpb6L4p1U\",\"type\":\"paragraph\",\"data\":{\"text\":\"Grab your favorite cup of coffee, open up your code editor, and let\u2019s dive in.\"}},{\"id\":\"hhFiA8iu8h\",\"type\":\"header\",\"data\":{\"text\":\"What Exactly is the <code>filter()<\/code> Method? (A Quick Refresher)\",\"level\":2}},{\"id\":\"QTjb6H2FeT\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before we jump into the complex interview questions, we need to ensure our foundational knowledge is rock solid.\"}},{\"id\":\"HirZHOPQg3\",\"type\":\"paragraph\",\"data\":{\"text\":\"The <code>filter()<\/code> method is a built-in JavaScript Array function that creates a <b>shallow copy<\/b> of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.\"}},{\"id\":\"y35oQfQouF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is the technical syntax:\"}},{\"id\":\"hkZRlkzgkX\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"JKEZjxHbj1\",\"type\":\"code\",\"data\":{\"code\":\"let newArray = originalArray.filter(callback(element, index, array), thisArg);\\n\"}},{\"id\":\"mOAxOG1mk_\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's break down these parameters, because an interviewer might just ask you what the third argument of the callback does!\"}},{\"id\":\"6L7Bq8rk4V\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"<b><code>callback<\/code><\/b>: The function that executes on each element in the array. It should return a truthy value to keep the element in the resulting array, and a falsy value to drop it.\",\"<b><code>element<\/code><\/b>: The current element being processed in the array.\",\"<b><code>index<\/code> (Optional)<\/b>: The index (position) of the current element being processed.\",\"<b><code>array<\/code> (Optional)<\/b>: The array that <code>filter()<\/code> was called upon.\",\"<b><code>thisArg<\/code> (Optional)<\/b>: A value to use as <code>this<\/code> when executing the callback. (Rarely used in modern ES6 arrow functions, but a good trivia point to know!).\"]}},{\"id\":\"qL7J1vq1_v\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Crucial Interview Fact:<\/b> The <code>filter()<\/code> method does <b>not<\/b> mutate (change) the original array. It always returns a brand new array. If no elements pass the test, it returns an empty array <code>[]<\/code>.\"}},{\"id\":\"LBjNU-9G1y\",\"type\":\"header\",\"data\":{\"text\":\"Why Do Interviewers Love Testing the <code>filter()<\/code> Method?\",\"level\":2}},{\"id\":\"u4gtO14Mwk\",\"type\":\"paragraph\",\"data\":{\"text\":\"You might be wondering, <i>\\\"Why do interviewers care so much about this specific method?\\\"<\/i>\"}},{\"id\":\"OPL-QP1hKV\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>It tests your understanding of Immutability:<\/b> In modern frameworks like React, mutating state directly is a massive anti-pattern. Interviewers want to see that you understand how to create new arrays rather than modifying existing ones using <code>.push()<\/code> or <code>.splice()<\/code>.\",\"<b>It tests Declarative vs. Imperative Programming:<\/b> Writing a <code>for<\/code> loop is imperative (you tell the computer <i>how<\/i> to do it). Using <code>filter()<\/code> is declarative (you tell the computer <i>what<\/i> you want). Modern JavaScript strongly favors declarative syntax.\",\"<b>It proves you understand Callbacks and Higher-Order Functions:<\/b> These are fundamental concepts in asynchronous JavaScript and functional programming.\"]}},{\"id\":\"XEfk1NIQXK\",\"type\":\"header\",\"data\":{\"text\":\"Top JavaScript <code>filter()<\/code> Interview Questions\",\"level\":2}},{\"id\":\"aVeGEqZ29c\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let's get into the meat of the article. Here are the most common <code>filter()<\/code> questions you will encounter, categorized by difficulty.\"}},{\"id\":\"M2_EeVlulJ\",\"type\":\"header\",\"data\":{\"text\":\"Level 1: The Warm-Up Questions\",\"level\":3}},{\"id\":\"k6_e-4uoHi\",\"type\":\"paragraph\",\"data\":{\"text\":\"These questions are usually asked at the very beginning of an interview to make sure you know the basic syntax. Don't rush them; explain your thought process clearly.\"}},{\"id\":\"qtTeFlhaZa\",\"type\":\"header\",\"data\":{\"text\":\"Question 1: Given an array of numbers, return only the even numbers.\",\"level\":4}},{\"id\":\"OFuqPvxIOZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is as basic as it gets, but it tests if you know how to use the modulo (<code>%<\/code>) operator.\"}},{\"id\":\"oL41X7oqSy\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"0l3iUuCllh\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"XsAHxhpw1r\",\"type\":\"code\",\"data\":{\"code\":\"const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];\\n\\nconst evenNumbers = numbers.filter(num => num % 2 === 0);\\n\\nconsole.log(evenNumbers); \\n\/\/ Output: [2, 4, 6, 8, 10]\\n\"}},{\"id\":\"T4Ui613gZg\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> Explain that the modulo operator returns the remainder of a division. If <code>num % 2<\/code> equals strictly zero, the number is even. The arrow function implicitly returns this boolean expression.\"}},{\"id\":\"44czqHaw3o\",\"type\":\"header\",\"data\":{\"text\":\"Question 2: Filter an array of strings to only include words with more than 5 characters.\",\"level\":4}},{\"id\":\"uMzXAfduDP\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"MRVOStiL1C\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"fwJriJewXA\",\"type\":\"code\",\"data\":{\"code\":\"const words = ['apple', 'banana', 'kiwi', 'strawberry', 'plum'];\\n\\nconst longWords = words.filter(word => word.length > 5);\\n\\nconsole.log(longWords); \\n\/\/ Output: ['banana', 'strawberry']\\n\"}},{\"id\":\"1a7pd8bwKZ\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> Mention that <code>filter<\/code> loops through each string and evaluates the <code>.length<\/code> property. Since 'apple' has exactly 5 characters, <code>5 &gt; 5<\/code> evaluates to false, so it is excluded.\"}},{\"id\":\"2pTN8VhfKd\",\"type\":\"header\",\"data\":{\"text\":\"Level 2: Intermediate Practical Questions\",\"level\":3}},{\"id\":\"4FE1HNFV-i\",\"type\":\"paragraph\",\"data\":{\"text\":\"These are the types of questions that mimic real-world tasks you would do on the job.\"}},{\"id\":\"WE5FZioTrH\",\"type\":\"header\",\"data\":{\"text\":\"Question 3: Filtering an Array of Objects based on multiple conditions.\",\"level\":4}},{\"id\":\"qgfdfenIy7\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Scenario:<\/i> \\\"We have an array of user objects from our database. I need you to give me an array of only the users who are active AND are over the age of 18.\\\"\"}},{\"id\":\"Lc5za9Fwky\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"vEjKZUR06U\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"-93j4PpTm1\",\"type\":\"code\",\"data\":{\"code\":\"const users = [\\n  { id: 1, name: 'Alice', age: 17, isActive: true },\\n  { id: 2, name: 'Bob', age: 22, isActive: false },\\n  { id: 3, name: 'Charlie', age: 25, isActive: true },\\n  { id: 4, name: 'Diana', age: 30, isActive: true }\\n];\\n\\nconst targetUsers = users.filter(user => user.isActive && user.age > 18);\\n\\nconsole.log(targetUsers);\\n\/* Output: \\n[\\n  { id: 3, name: 'Charlie', age: 25, isActive: true },\\n  { id: 4, name: 'Diana', age: 30, isActive: true }\\n]\\n*\/\\n\"}},{\"id\":\"GWcYpM39EW\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> Show that you can combine boolean logic using the logical AND (<code>&amp;&amp;<\/code>) operator. You should also mention that the objects inside the new array are shallow copies (references) to the objects in the original array. If you change <code>targetUsers[0].name<\/code>, it will change in the <code>users<\/code> array too! (Mentioning this will earn you massive bonus points).\"}},{\"id\":\"Hc7ONwvmMK\",\"type\":\"header\",\"data\":{\"text\":\"Question 4: Clean up this array by removing all falsy values.\",\"level\":4}},{\"id\":\"e5AEbP_F0o\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Scenario:<\/i> \\\"We have an array of messy data containing nulls, undefined, and empty strings. Clean it up.\\\"\"}},{\"id\":\"4vp7gTbD8Z\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"JKee6S_kwC\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"LN48UFItYs\",\"type\":\"code\",\"data\":{\"code\":\"const messyData = [0, \\\"hello\\\", false, \\\"\\\", undefined, 42, null, \\\"world\\\", NaN];\\n\\n\/\/ Method 1: The standard way\\nconst cleanData1 = messyData.filter(item => Boolean(item));\\n\\n\/\/ Method 2: The clever, senior-developer way\\nconst cleanData2 = messyData.filter(Boolean);\\n\\nconsole.log(cleanData2); \\n\/\/ Output: ['hello', 42, 'world']\\n\"}},{\"id\":\"5m8qyfMmZr\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> First, you must know what the falsy values in JavaScript are (<code>false<\/code>, <code>0<\/code>, <code>\\\"\\\"<\/code>, <code>null<\/code>, <code>undefined<\/code>, and <code>NaN<\/code>). Secondly, explaining Method 2 will impress them. By passing the <code>Boolean<\/code> constructor function directly as the callback, <code>filter<\/code> automatically passes each item into <code>Boolean()<\/code>, cleanly and efficiently stripping out anything falsy.\"}},{\"id\":\"oH_U6X0-pY\",\"type\":\"header\",\"data\":{\"text\":\"Level 3: The Theory Questions (No Code Allowed)\",\"level\":3}},{\"id\":\"yp3RL5Z86J\",\"type\":\"paragraph\",\"data\":{\"text\":\"Sometimes, the interviewer will stop you from typing and ask you to explain concepts verbally.\"}},{\"id\":\"HQgMUHQnCG\",\"type\":\"header\",\"data\":{\"text\":\"Question 5: What is the difference between <code>filter()<\/code> and <code>find()<\/code>?\",\"level\":4}},{\"id\":\"vR8zpac8mT\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Your Answer:<\/b>\"}},{\"id\":\"Kblfl1khZF\",\"type\":\"paragraph\",\"data\":{\"text\":\"\\\"Both iterate through an array based on a condition, but they serve different purposes. <code>filter()<\/code> returns a <b>new array<\/b> containing <i>all<\/i> elements that match the condition. If none match, it returns an empty array <code>[]<\/code>.\"}},{\"id\":\"47UlmLHYEp\",\"type\":\"paragraph\",\"data\":{\"text\":\"On the other hand, <code>find()<\/code> returns the <b>value of the first element<\/b> that matches the condition and immediately stops iterating. If nothing matches, it returns <code>undefined<\/code>. If I know there should only be one unique match (like finding a user by their unique ID), I would use <code>find()<\/code> for better performance and a more logical return type.\\\"\"}},{\"id\":\"TcFP5JmRPA\",\"type\":\"header\",\"data\":{\"text\":\"Question 6: What is the difference between <code>filter()<\/code> and <code>map()<\/code>?\",\"level\":4}},{\"id\":\"bYkYBqFP7C\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Your Answer:<\/b>\"}},{\"id\":\"CNpBkJmT4t\",\"type\":\"paragraph\",\"data\":{\"text\":\"\\\"<code>filter()<\/code> is used to remove items from an array. The resulting array will usually be shorter than the original array, but the elements inside it remain identical to the originals. The callback must return a boolean.\"}},{\"id\":\"fPVAthk_lW\",\"type\":\"paragraph\",\"data\":{\"text\":\"<code>map()<\/code> is used to transform items in an array. The resulting array will always be the exact same length as the original array, but the elements inside will be modified based on what you return from the callback.\\\"\"}},{\"id\":\"CztFRkXeVe\",\"type\":\"header\",\"data\":{\"text\":\"Level 4: Advanced Architectural Questions\",\"level\":3}},{\"id\":\"tnjhGlOV5w\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is where you secure the Senior Developer title and negotiate the upper end of the salary band.\"}},{\"id\":\"23jevN_Zk1\",\"type\":\"header\",\"data\":{\"text\":\"Question 7: How would you remove duplicate values from an array using <code>filter<\/code>?\",\"level\":4}},{\"id\":\"41couVnOxx\",\"type\":\"paragraph\",\"data\":{\"text\":\"Wait, isn't there a <code>Set<\/code> object for this? Yes, <code>[...new Set(array)]<\/code> is the modern way. But interviewers often restrict you to only using <code>filter()<\/code> to test your understanding of its extra parameters (<code>index<\/code> and <code>array<\/code>).\"}},{\"id\":\"uBXbf-8qDX\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"rzbvV_nAS9\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"4l20s4SuyJ\",\"type\":\"code\",\"data\":{\"code\":\"const duplicates = [\\\"apple\\\", \\\"banana\\\", \\\"apple\\\", \\\"orange\\\", \\\"banana\\\", \\\"kiwi\\\"];\\n\\nconst uniqueFruits = duplicates.filter((item, index, arr) => {\\n  \/\/ We check if the FIRST occurrence of the item matches the current index\\n  return arr.indexOf(item) === index;\\n});\\n\\nconsole.log(uniqueFruits);\\n\/\/ Output: ['apple', 'banana', 'orange', 'kiwi']\\n\"}},{\"id\":\"SN7Utl6o17\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> You need to explain the mechanics clearly. <code>indexOf()<\/code> always returns the index of the <i>first<\/i> time it finds a specific string. As <code>filter<\/code> loops through, when it hits the second \\\"apple\\\" (at index 2), <code>arr.indexOf(\\\"apple\\\")<\/code> still returns 0. Since <code>0 !== 2<\/code>, the duplicate is filtered out. It is a brilliant display of utilizing all three of <code>filter<\/code>'s callback arguments.\"}},{\"id\":\"QbiFChar5g\",\"type\":\"header\",\"data\":{\"text\":\"Question 8: Chaining <code>filter()<\/code> with <code>map()<\/code> and <code>reduce()<\/code>\",\"level\":4}},{\"id\":\"a5ywjChT2W\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Scenario:<\/i> \\\"Here is an array of orders. I want you to find all the orders that are completed, extract just their total prices, and calculate the total revenue.\\\"\"}},{\"id\":\"eJdnrPh5Hr\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"bcakbr7RY_\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"1-QcN4IK2L\",\"type\":\"code\",\"data\":{\"code\":\"const orders = [\\n  { id: 1, status: 'completed', total: 150 },\\n  { id: 2, status: 'pending', total: 200 },\\n  { id: 3, status: 'completed', total: 50 },\\n  { id: 4, status: 'cancelled', total: 120 }\\n];\\n\\nconst totalRevenue = orders\\n  .filter(order => order.status === 'completed') \/\/ Step 1: Filter out pending\/cancelled\\n  .map(order => order.total)                     \/\/ Step 2: Extract just the numbers [150, 50]\\n  .reduce((acc, current) => acc + current, 0);   \/\/ Step 3: Add them up\\n\\nconsole.log(`Total Revenue: $${totalRevenue}`);\\n\/\/ Output: Total Revenue: $200\\n\"}},{\"id\":\"P5pBfFBAVM\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>What the interviewer wants to hear:<\/b> This demonstrates your ability to build data pipelines. Because <code>filter<\/code> and <code>map<\/code> return arrays, you can chain them directly into each other. Talk about how this makes the code highly readable and declarative, like reading a sentence in plain English.\"}},{\"id\":\"TQuWEsWUBH\",\"type\":\"header\",\"data\":{\"text\":\"The Final Boss: Writing a Custom Polyfill for <code>filter()<\/code>\",\"level\":3}},{\"id\":\"EsFuYn3y10\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you are interviewing for a mid-to-senior frontend role (especially at FAANG\/MAANG companies), you might be asked: <i>\\\"Can you write your own version of <code>filter()<\/code> from scratch?\\\"<\/i>\"}},{\"id\":\"R8qhcHuMB4\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is called writing a polyfill. It proves you understand how JavaScript engines actually implement these built-in methods under the hood.\"}},{\"id\":\"S01iLC0eWl\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Strategy:<\/b>\"}},{\"id\":\"ytDZMXHO22\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"We need to add a method to <code>Array.prototype<\/code>.\",\"We need to create a new, empty array to store the results.\",\"We need to loop over <code>this<\/code> (which refers to the array calling the method).\",\"We need to execute the user's callback function, passing in the element, index, and the array itself.\",\"If the callback evaluates to true, we push the item to our new array.\",\"Return the new array.\"]}},{\"id\":\"KYVtTe7X-f\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Code:<\/b>\"}},{\"id\":\"NuDBClSs5t\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"9TRxr2t4Aj\",\"type\":\"code\",\"data\":{\"code\":\"\/\/ Adding our custom method to the Array prototype\\nArray.prototype.myFilter = function(callback, thisArg) {\\n  \\n  \/\/ Error handling (good practice to mention in interviews!)\\n  if (typeof callback !== 'function') {\\n    throw new TypeError(callback + ' is not a function');\\n  }\\n\\n  \/\/ The array to be returned\\n  const result = [];\\n  \\n  \/\/ 'this' refers to the array the method was called on\\n  for (let i = 0; i < this.length; i++) {\\n    \/\/ Check if the property actually exists (to handle sparse arrays)\\n    if (Object.hasOwn(this, i)) {\\n      \/\/ Execute callback, utilizing thisArg if provided\\n      if (callback.call(thisArg, this[i], i, this)) {\\n        result.push(this[i]);\\n      }\\n    }\\n  }\\n  \\n  return result;\\n};\\n\\n\/\/ Let's test it!\\nconst numbers = [1, 2, 3, 4, 5];\\nconst evens = numbers.myFilter(num => num % 2 === 0);\\nconsole.log(evens); \/\/ Output: [2, 4]\\n\"}},{\"id\":\"ZP9S1BpVUk\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Why this code blows interviewers away:<\/b>\"}},{\"id\":\"Sc54kityVD\",\"type\":\"list\",\"data\":{\"style\":\"unordered\",\"items\":[\"You handled error checking (<code>TypeError<\/code>).\",\"You used the <code>this<\/code> keyword correctly to reference the parent array.\",\"You handled the optional <code>thisArg<\/code> using <code>.call()<\/code>.\",\"You handled \\\"sparse arrays\\\" (arrays with empty slots like <code>[1, , 3]<\/code>) by checking <code>Object.hasOwn(this, i)<\/code> (or <code>i in this<\/code>). Standard built-in <code>filter<\/code> skips empty slots, so your polyfill should too!\"]}},{\"id\":\"z16sYMFkiI\",\"type\":\"header\",\"data\":{\"text\":\"Common Mistakes and Traps to Avoid in Interviews\",\"level\":2}},{\"id\":\"r_0dHHb866\",\"type\":\"paragraph\",\"data\":{\"text\":\"As we wrap up, I want to leave you with a few common pitfalls that nervous candidates fall into. Keep these in mind to keep your composure during the whiteboard session.\"}},{\"id\":\"ZmLUNtKEG1\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Forgetting to <code>return<\/code> in standard functions:<\/b> If you use curly braces <code>{}<\/code> in an arrow function, you <i>must<\/i> explicitly write the <code>return<\/code> keyword.<i>Bad:<\/i> <code>array.filter(item =&gt; { item &gt; 5 })<\/code> (Returns an empty array).<i>Good:<\/i> <code>array.filter(item =&gt; item &gt; 5)<\/code> OR <code>array.filter(item =&gt; { return item &gt; 5; })<\/code>\",\"<i>Bad:<\/i> <code>array.filter(item =&gt; { item &gt; 5 })<\/code> (Returns an empty array).\",\"<i>Good:<\/i> <code>array.filter(item =&gt; item &gt; 5)<\/code> OR <code>array.filter(item =&gt; { return item &gt; 5; })<\/code>\",\"<b>Trying to use <code>break<\/code> or <code>continue<\/code>:<\/b> You cannot use <code>break<\/code> or <code>continue<\/code> inside a <code>filter()<\/code> callback like you can in a standard <code>for<\/code> loop. If you need to stop iteration early based on a condition, you should be using a standard <code>for<\/code> loop or the <code>some()<\/code>\/<code>every()<\/code> methods.\",\"<b>Worrying about Performance too early:<\/b> Yes, chaining <code>.filter().map()<\/code> loops through the array twice, which is technically <code>O(n + n)<\/code> time complexity. While a single <code>reduce()<\/code> or <code>for<\/code> loop could do both in one pass (<code>O(n)<\/code>), the declarative readability of chaining is usually preferred in modern development unless you are dealing with arrays of hundreds of thousands of items. If performance comes up, state exactly that: <i>\\\"Readability first, optimize if data scaling becomes an issue.\\\"<\/i>\"]}},{\"id\":\"xm4O0a-XYI\",\"type\":\"header\",\"data\":{\"text\":\"Final Thoughts\",\"level\":2}},{\"id\":\"8kJnfKa4B3\",\"type\":\"paragraph\",\"data\":{\"text\":\"The JavaScript <code>filter()<\/code> method is much more than just a convenient utility tool; it is a gateway into functional programming paradigms in JavaScript. By understanding its inner workings, its quirks, and its relationship with other array methods, you aren't just memorizing interview answers\u2014you are becoming a better, more thoughtful JavaScript developer.\"}},{\"id\":\"xbp2MFvORM\",\"type\":\"embed\",\"data\":{\"service\":\"youtube\",\"source\":\"https:\/\/youtu.be\/YgwAYQr6kHk?si=rZJpNzf5PBHIHATV\",\"embed\":\"https:\/\/www.youtube.com\/embed\/YgwAYQr6kHk?\",\"width\":580,\"height\":320,\"caption\":\"\"}},{\"id\":\"dV7W4s1xLU\",\"type\":\"paragraph\",\"data\":{\"text\":\"When you walk into your next interview, don't just write the code. Explain <i>why<\/i> you are writing it. Talk about immutability. Mention shallow copies. Bring up declarative programming. If you communicate your thought process using the concepts we discussed above, you won't just pass the interview\u2014you'll completely dominate it.\"}},{\"id\":\"e85wNcA1gg\",\"type\":\"paragraph\",\"data\":{\"text\":\"Good luck, keep coding, and go crush that interview!\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/javascript-filter-method-interview-questions-1786289100.png","status":"published","excerpt":"Preparing for a frontend developer interview? Dive deep into the JavaScript filter() method. Explore top interview questions, real-world examples, advanced chaining, and how to write a custom polyfill.","published_at":"2026-08-09T15:24:56.185000Z","tags":"[\"web-development\",\"javascript\",\"frontend\",\"frontend-development\",\"web-development-tutorial\"]","created_at":"2026-08-09T15:25:00.000000Z","updated_at":"2026-11-23T17:31:36.000000Z","views":43,"scheduled_at":null,"score":1786289186},{"id":13,"user_id":1,"category_id":2,"title":"Difference Between Var, Let, and Const in JavaScript | Interview Guide","slug":"difference-between-var-let-and-const-in-javascript-interview-guide","content":"{\"time\":1786197938253,\"blocks\":[{\"id\":\"3j6s4m-TVg\",\"type\":\"header\",\"data\":{\"text\":\"Demystifying JavaScript Variables: The Ultimate Guide to Var, Let, and Const for Interviews\",\"level\":2}},{\"id\":\"OIU0J-wt7b\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you are stepping into a JavaScript interview, whether it is for a junior front-end role or a senior full-stack position, there is one question you are almost guaranteed to face: <i>\\\"Can you explain the difference between <code>var<\/code>, <code>let<\/code>, and <code>const<\/code>?\\\"<\/i>\"}},{\"id\":\"04s7-fX5PV\",\"type\":\"paragraph\",\"data\":{\"text\":\"On the surface, it feels like a simple question. You might think, <i>\\\"Well, <code>var<\/code> is old, <code>let<\/code> is new, and <code>const<\/code> cannot be changed.\\\"<\/i> While that is functionally true, answering it that simply in an interview is a missed opportunity. Interviewers do not just want to know <i>how<\/i> to use them; they want to know if you understand <i>how the JavaScript engine treats them<\/i> under the hood. They are listening for keywords like <b>Scope<\/b>, <b>Hoisting<\/b>, <b>Reassignment<\/b>, and the dreaded <b>Temporal Dead Zone (TDZ)<\/b>.\"}},{\"id\":\"tLqnqwaxPW\",\"type\":\"paragraph\",\"data\":{\"text\":\"In this comprehensive guide, we are going to break down these three variable declarations like never before. We will look at how the JavaScript engine reads your code, explore real-world analogies, and tackle the exact trap questions interviewers use to test your true understanding.\"}},{\"id\":\"p2u_z2V2mY\",\"type\":\"paragraph\",\"data\":{\"text\":\"Grab a cup of coffee, open your code editor, and let us dive deep into the world of JavaScript variables.\"}},{\"id\":\"7bKE2BoLPi\",\"type\":\"header\",\"data\":{\"text\":\"The Pre-requisites: Scope and Hoisting\",\"level\":2}},{\"id\":\"4WOUlw61Bt\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before we can accurately compare <code>var<\/code>, <code>let<\/code>, and <code>const<\/code>, we need to understand the environment they live in. If you do not understand Scope and Hoisting, the differences between these variables will just feel like arbitrary rules you have to memorize.\"}},{\"id\":\"sACcYHmC-v\",\"type\":\"header\",\"data\":{\"text\":\"What is Scope?\",\"level\":3}},{\"id\":\"xAqwZEC4Lj\",\"type\":\"paragraph\",\"data\":{\"text\":\"Think of \\\"Scope\\\" as the visibility or lifespan of a variable. It dictates where in your code a specific variable can be accessed, modified, or seen. JavaScript traditionally had two types of scope, but ES6 (ECMAScript 2015) introduced a third.\"}},{\"id\":\"lHBPY383G5\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"<b>Global Scope:<\/b> A variable declared outside of any function or block. It is visible to everything, everywhere in your JavaScript file. (Think of this as a public billboard).\",\"<b>Function Scope:<\/b> Variables declared inside a function are locked inside that function. The outside world cannot see them. (Think of this as a secure office building).\",\"<b>Block Scope:<\/b> A block is any code wrapped inside curly braces <code>{}<\/code>. This could be an <code>if<\/code> statement, a <code>for<\/code> loop, or just empty brackets. Block scope means a variable is locked specifically inside those brackets. (Think of this as a private meeting room inside the office building).\"]}},{\"id\":\"0e-xVTggDd\",\"type\":\"header\",\"data\":{\"text\":\"What is Hoisting?\",\"level\":3}},{\"id\":\"tQ6BTMv3mE\",\"type\":\"paragraph\",\"data\":{\"text\":\"Hoisting is often explained as \\\"JavaScript moving your variables to the top of the file.\\\" But that is a myth. Nothing actually moves.\"}},{\"id\":\"27dRyYYbXb\",\"type\":\"paragraph\",\"data\":{\"text\":\"Instead, when you run a JavaScript file, the engine goes through a <b>Memory Creation Phase<\/b> before it executes a single line of code. It scans your document for variables and functions, and allocates memory space for them <i>before<\/i> running the code line by line. How <code>var<\/code>, <code>let<\/code>, and <code>const<\/code> react to this memory phase is one of their biggest differences.\"}},{\"id\":\"EHLOGGFc4e\",\"type\":\"paragraph\",\"data\":{\"text\":\"Now that we have the foundation, let us tear down each variable type.\"}},{\"id\":\"DrPEHdaGnS\",\"type\":\"header\",\"data\":{\"text\":\"1. The Wild West: <code>var<\/code>\",\"level\":2}},{\"id\":\"EaBB-y8fUM\",\"type\":\"paragraph\",\"data\":{\"text\":\"Before 2015, <code>var<\/code> was the only way to declare variables in JavaScript. It is old, it is unpredictable, and quite frankly, it has caused millions of hours of debugging headaches for developers around the world.\"}},{\"id\":\"spmXTdQxE4\",\"type\":\"header\",\"data\":{\"text\":\"Scope: Function Scoped\",\"level\":3}},{\"id\":\"MzxBalu_5E\",\"type\":\"paragraph\",\"data\":{\"text\":\"The biggest defining feature of <code>var<\/code> is that it is <b>function scoped<\/b>, but it is <i>not<\/i> block scoped. If you declare a <code>var<\/code> inside an <code>if<\/code> statement or a <code>for<\/code> loop, it ignores those curly braces and leaks out into the surrounding function (or into the global scope).\"}},{\"id\":\"75OIvyBgLa\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"IrGDWa-2Xj\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"wL0iEgsUqv\",\"type\":\"code\",\"data\":{\"code\":\"function testVarScope() {\\n    if (true) {\\n        var secretMessage = \\\"I am a secret!\\\";\\n    }\\n    \/\/ We can still access it outside the 'if' block!\\n    console.log(secretMessage); \/\/ Output: \\\"I am a secret!\\\"\\n}\\n\\ntestVarScope();\\n\"}},{\"id\":\"9ZTG76TvW4\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Why is this bad?<\/i> Because if you have a massive file and you use <code>var counter = 0<\/code> inside a loop, you might accidentally overwrite another <code>counter<\/code> variable you created somewhere else in the same function. It causes silent bugs that are incredibly hard to track down.\"}},{\"id\":\"OsPcKDSsVF\",\"type\":\"header\",\"data\":{\"text\":\"Hoisting: Initialized as <code>undefined<\/code>\",\"level\":3}},{\"id\":\"EIV-I0ptK2\",\"type\":\"paragraph\",\"data\":{\"text\":\"When the JavaScript engine does its memory sweep (Hoisting), it spots <code>var<\/code> declarations, sets aside memory for them, and immediately assigns them a default value of <code>undefined<\/code>.\"}},{\"id\":\"oQt-b7bKZF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Because of this, you can actually try to log a <code>var<\/code> variable <i>before<\/i> you write the line of code that declares it, and your app will not crash.\"}},{\"id\":\"3T7kQnUcu9\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"w1DYU3ty7X\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"LDkgj0FSl-\",\"type\":\"code\",\"data\":{\"code\":\"console.log(companyName); \/\/ Output: undefined\\nvar companyName = \\\"Tech Solutions Inc.\\\";\\nconsole.log(companyName); \/\/ Output: \\\"Tech Solutions Inc.\\\"\\n\"}},{\"id\":\"9XdpAgi9L6\",\"type\":\"header\",\"data\":{\"text\":\"Re-declaration and Re-assignment\",\"level\":3}},{\"id\":\"oF2cdt0qo6\",\"type\":\"paragraph\",\"data\":{\"text\":\"<code>var<\/code> is completely reckless. You can re-assign its value, and worse, you can completely re-declare it in the same scope without JavaScript throwing an error.\"}},{\"id\":\"IVQORG7dzY\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"OdmHp9orEX\",\"type\":\"code\",\"data\":{\"code\":\"var userAge = 25;\\nvar userAge = 30; \/\/ No error! The engine just shrugs and overwrites it.\\n\"}},{\"id\":\"P3sCmnmM7I\",\"type\":\"header\",\"data\":{\"text\":\"Real-World Analogy for <code>var<\/code>\",\"level\":3}},{\"id\":\"2FhfVH0yK6\",\"type\":\"paragraph\",\"data\":{\"text\":\"Imagine <code>var<\/code> as the office gossip. You tell them a secret inside a private meeting room (a block), but the moment the door opens, they leak that information to the entire office floor (function scope). Furthermore, if someone tells them a different version of the story (re-declaration), they instantly forget the old one without telling anyone.\"}},{\"id\":\"7w4u9T5kBM\",\"type\":\"header\",\"data\":{\"text\":\"2. The Reliable Professional: <code>let<\/code>\",\"level\":2}},{\"id\":\"kNg3YGmMjG\",\"type\":\"paragraph\",\"data\":{\"text\":\"When ES6 arrived in 2015, it brought <code>let<\/code> and <code>const<\/code> to fix the mess that <code>var<\/code> had created. <code>let<\/code> is the modern standard for variables that need to change over time (like counters, toggles, or dynamic strings).\"}},{\"id\":\"Myn5QKtMZK\",\"type\":\"header\",\"data\":{\"text\":\"Scope: Block Scoped\",\"level\":3}},{\"id\":\"suE0zS2gqz\",\"type\":\"paragraph\",\"data\":{\"text\":\"Unlike <code>var<\/code>, <code>let<\/code> respects curly braces. If you create a <code>let<\/code> variable inside an <code>if<\/code> block, a <code>for<\/code> loop, or a <code>while<\/code> loop, it stays trapped inside those braces. It is strictly <b>block scoped<\/b>.\"}},{\"id\":\"k8Lyl-1m7q\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"XPO4rqpRut\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"-GD3PbxoCe\",\"type\":\"code\",\"data\":{\"code\":\"function testLetScope() {\\n    if (true) {\\n        let secureMessage = \\\"Top Secret!\\\";\\n        console.log(secureMessage); \/\/ Works perfectly here\\n    }\\n    \/\/ Trying to access it outside the block:\\n    console.log(secureMessage); \/\/ ReferenceError: secureMessage is not defined\\n}\\n\\ntestLetScope();\\n\"}},{\"id\":\"QV01HyirXI\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is a massive upgrade. It means developers can confidently name variables inside loops without fearing they will accidentally overwrite data globally.\"}},{\"id\":\"_-ZeLsH1rR\",\"type\":\"header\",\"data\":{\"text\":\"Hoisting and The Temporal Dead Zone (TDZ)\",\"level\":3}},{\"id\":\"5RTggEV0mX\",\"type\":\"paragraph\",\"data\":{\"text\":\"This is the most critical part of an interview answer. <b>Does <code>let<\/code> get hoisted? YES.<\/b>\"}},{\"id\":\"pwwBuX415d\",\"type\":\"paragraph\",\"data\":{\"text\":\"Many developers incorrectly say that <code>let<\/code> and <code>const<\/code> are not hoisted. They absolutely are. The JavaScript engine allocates memory for them during the creation phase. However, unlike <code>var<\/code> (which gets initialized with <code>undefined<\/code>), <code>let<\/code> and <code>const<\/code> remain <b>uninitialized<\/b>.\"}},{\"id\":\"pd0SSluBAL\",\"type\":\"paragraph\",\"data\":{\"text\":\"The time between the start of the block and the exact line of code where the variable is declared is known as the <b>Temporal Dead Zone (TDZ)<\/b>. If you try to access the variable while it is in the TDZ, JavaScript will throw a strict error.\"}},{\"id\":\"ANNbDSwKhD\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"PkaKDf3NBn\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"tfqj9zwdOA\",\"type\":\"code\",\"data\":{\"code\":\"\/\/ Temporal Dead Zone starts here for 'projectName'\\nconsole.log(projectName); \/\/ ReferenceError: Cannot access 'projectName' before initialization\\n\\nlet projectName = \\\"Apollo\\\"; \/\/ TDZ ends here. Variable is initialized.\\nconsole.log(projectName); \/\/ Output: \\\"Apollo\\\"\\n\"}},{\"id\":\"_CD4JPVY5a\",\"type\":\"paragraph\",\"data\":{\"text\":\"The TDZ is a safety mechanism. It forces you to write clean, top-down code and prevents you from using variables before they hold actual data.\"}},{\"id\":\"Jq190BZVwz\",\"type\":\"header\",\"data\":{\"text\":\"Re-declaration and Re-assignment\",\"level\":3}},{\"id\":\"VEKz1vig3n\",\"type\":\"paragraph\",\"data\":{\"text\":\"With <code>let<\/code>, you <i>can<\/i> re-assign the value later on. However, you <i>cannot<\/i> re-declare the same variable name in the same scope. This prevents accidental overwriting.\"}},{\"id\":\"DoF2O2gltD\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"CxPamKZ0ow\",\"type\":\"code\",\"data\":{\"code\":\"let score = 10;\\nscore = 15; \/\/ Re-assignment is totally fine.\\n\\nlet score = 20; \/\/ SyntaxError: Identifier 'score' has already been declared\\n\"}},{\"id\":\"1wpU_WaeVy\",\"type\":\"header\",\"data\":{\"text\":\"Real-World Analogy for <code>let<\/code>\",\"level\":3}},{\"id\":\"n4Jzqtv6CF\",\"type\":\"paragraph\",\"data\":{\"text\":\"Imagine <code>let<\/code> as a whiteboard in a private meeting room (block scope). Only the people inside that specific room can see and update the whiteboard. You can erase the whiteboard and write new numbers on it (re-assignment), but you cannot bring a second whiteboard into the exact same room and give it the exact same name (no re-declaration).\"}},{\"id\":\"vzz6G4lblP\",\"type\":\"header\",\"data\":{\"text\":\"3. The Unbreakable Vow: <code>const<\/code>\",\"level\":2}},{\"id\":\"Bbea2o80AK\",\"type\":\"paragraph\",\"data\":{\"text\":\"<code>const<\/code> stands for \\\"constant.\\\" You should use <code>const<\/code> by default for almost everything in modern JavaScript, unless you explicitly know the value needs to change (in which case, use <code>let<\/code>).\"}},{\"id\":\"N-XKJ0RJhg\",\"type\":\"header\",\"data\":{\"text\":\"Scope and Hoisting\",\"level\":3}},{\"id\":\"rRJSF9MmMP\",\"type\":\"paragraph\",\"data\":{\"text\":\"<code>const<\/code> behaves exactly like <code>let<\/code> in terms of scope and hoisting.\"}},{\"id\":\"o9JRdmPMqP\",\"type\":\"list\",\"data\":{\"style\":\"ordered\",\"items\":[\"It is <b>Block Scoped<\/b> (respects curly braces <code>{}<\/code>).\",\"It is <b>Hoisted<\/b> but placed in the <b>Temporal Dead Zone<\/b>, meaning you cannot access it before initialization.\"]}},{\"id\":\"rikIlO_H4U\",\"type\":\"header\",\"data\":{\"text\":\"Re-declaration and Re-assignment\",\"level\":3}},{\"id\":\"6RytBsGS3k\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is where <code>const<\/code> differs from <code>let<\/code>.\"}},{\"id\":\"aSHAitUV25\",\"type\":\"paragraph\",\"data\":{\"text\":\"With <code>const<\/code>, you <b>cannot re-declare<\/b> it, and you <b>cannot re-assign<\/b> it. Once a primitive value (like a String, Number, or Boolean) is locked into a <code>const<\/code> variable, it is set in stone. Furthermore, you must initialize a <code>const<\/code> at the exact time you declare it.\"}},{\"id\":\"v48OT5jsPX\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"zw75ZIgTvU\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"YA9s11X_ha\",\"type\":\"code\",\"data\":{\"code\":\"\/\/ This will throw a SyntaxError immediately. You must assign a value!\\nconst apiBaseUrl; \\n\\nconst pi = 3.14159;\\npi = 3.14; \/\/ TypeError: Assignment to constant variable.\\n\"}},{\"id\":\"gb1WW1Podq\",\"type\":\"header\",\"data\":{\"text\":\"The Ultimate Interview Trap: Mutability vs. Re-assignment\",\"level\":3}},{\"id\":\"dQqLXye5r5\",\"type\":\"paragraph\",\"data\":{\"text\":\"Interviewers love this trap. They will ask: <i>\\\"Can you change the value of a <code>const<\/code> variable?\\\"<\/i>\"}},{\"id\":\"liLBkj4iqt\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you say \\\"No, never,\\\" you have fallen into the trap.\"}},{\"id\":\"2m-nAyT5_h\",\"type\":\"paragraph\",\"data\":{\"text\":\"The correct answer is: <b>It depends on the data type.<\/b>\"}},{\"id\":\"8n_xzA6VlK\",\"type\":\"paragraph\",\"data\":{\"text\":\"<code>const<\/code> prevents <i>re-assignment<\/i> of the memory address. If you use primitive types (strings, numbers), they cannot be changed. But if you assign an <b>Object<\/b> or an <b>Array<\/b> to a <code>const<\/code>, the <i>reference<\/i> to that object is locked, but the <i>contents<\/i> inside the object are highly mutable (changeable).\"}},{\"id\":\"EiM4WRmvV7\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>Code Example:<\/b>\"}},{\"id\":\"759FosV66x\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"zeY62LVuKH\",\"type\":\"code\",\"data\":{\"code\":\"const userProfile = {\\n    name: \\\"Rahul\\\",\\n    role: \\\"MERN Developer\\\"\\n};\\n\\n\/\/ This is perfectly legal! We are modifying the contents, not re-assigning the variable.\\nuserProfile.role = \\\"Senior Architect\\\"; \\nconsole.log(userProfile.role); \/\/ Output: \\\"Senior Architect\\\"\\n\\n\/\/ This will fail! We are trying to point 'userProfile' to a brand new object.\\nuserProfile = { name: \\\"Amit\\\" }; \/\/ TypeError: Assignment to constant variable.\\n\"}},{\"id\":\"WU_KWhRiWA\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you truly want an object to be completely locked down and unchangeable, you have to use a specific JavaScript method called <code>Object.freeze()<\/code>.\"}},{\"id\":\"tC1PTTthLB\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"fzCARobyaK\",\"type\":\"code\",\"data\":{\"code\":\"const config = Object.freeze({ theme: \\\"dark\\\" });\\nconfig.theme = \\\"light\\\"; \/\/ Fails silently, or throws error in strict mode.\\n\"}},{\"id\":\"k-E_RWVU1i\",\"type\":\"header\",\"data\":{\"text\":\"Real-World Analogy for <code>const<\/code>\",\"level\":3}},{\"id\":\"gCNOfLaNuj\",\"type\":\"paragraph\",\"data\":{\"text\":\"Think of <code>const<\/code> like a permanent ID Card lanyard given to an employee. You cannot give them a completely different lanyard (no re-assignment). However, if there is a clear plastic pouch on that lanyard (an Object\/Array), you can easily take out the old ID paper and slide in a new one with an updated job title (mutating the contents).\"}},{\"id\":\"svZbYxych7\",\"type\":\"header\",\"data\":{\"text\":\"The Ultimate Quick Reference Guide\",\"level\":2}},{\"id\":\"4wGS5w671X\",\"type\":\"paragraph\",\"data\":{\"text\":\"If you need to quickly review before an interview, memorize this table.\"}},{\"id\":\"fFTUHswHAE\",\"type\":\"paragraph\",\"data\":{\"text\":\"Featurevarletconst<b>Scope<\/b>Function \/ GlobalBlock (<code>{}<\/code>)Block (<code>{}<\/code>)<b>Hoisting<\/b>Yes (Initialized to <code>undefined<\/code>)Yes (Uninitialized)Yes (Uninitialized)<b>Temporal Dead Zone (TDZ)<\/b>NoYesYes<b>Can Re-declare?<\/b>YesNoNo<b>Can Re-assign?<\/b>YesYesNo<b>Must Initialize upon Declaration?<\/b>NoNoYes\"}},{\"id\":\"3gAiBZxU8a\",\"type\":\"header\",\"data\":{\"text\":\"Real Interview Q&amp;A Walkthrough\",\"level\":2}},{\"id\":\"9xfBmfOtMh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Let us look at a few advanced scenarios interviewers use to test your mastery of these concepts.\"}},{\"id\":\"wM9zfc_ZDo\",\"type\":\"header\",\"data\":{\"text\":\"Interview Question 1: The Loop and the Timeout Trap\",\"level\":3}},{\"id\":\"DCkZtVi4yr\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Setup:<\/b> An interviewer slides you this piece of code and asks, \\\"What will this output to the console?\\\"\"}},{\"id\":\"JNvDLSYszs\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"rUY89IjW51\",\"type\":\"code\",\"data\":{\"code\":\"for (var i = 0; i < 3; i++) {\\n    setTimeout(function() {\\n        console.log(i);\\n    }, 1000);\\n}\\n\"}},{\"id\":\"lFRSufaxYE\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>How to Answer:<\/b>\"}},{\"id\":\"CaRB2V8KNn\",\"type\":\"paragraph\",\"data\":{\"text\":\"Most beginners guess <code>0, 1, 2<\/code>. The correct answer is <b><code>3, 3, 3<\/code><\/b>.\"}},{\"id\":\"d3chYJfEcc\",\"type\":\"paragraph\",\"data\":{\"text\":\"Here is why: <code>var<\/code> is function scoped, not block scoped. By the time the <code>setTimeout<\/code> finishes waiting for 1 second, the <code>for<\/code> loop has already finished running. The single variable <code>i<\/code> sitting in memory is now <code>3<\/code>. All three timeouts look at the exact same variable <code>i<\/code> and print <code>3<\/code>.\"}},{\"id\":\"LHm7Quxv0E\",\"type\":\"paragraph\",\"data\":{\"text\":\"To fix this, simply change <code>var<\/code> to <code>let<\/code>. Because <code>let<\/code> is block scoped, a brand new memory binding is created for <code>i<\/code> <i>every single iteration of the loop<\/i>. If you use <code>let<\/code>, the output will correctly be <code>0, 1, 2<\/code>.\"}},{\"id\":\"CTTtay3VJU\",\"type\":\"header\",\"data\":{\"text\":\"Interview Question 2: Accessing variables before initialization\",\"level\":3}},{\"id\":\"9ebe9HBBrI\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>The Setup:<\/b> \\\"Can you explain the difference in error outputs between these two blocks of code?\\\"\"}},{\"id\":\"YanQSuBlio\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Block A:<\/i>\"}},{\"id\":\"UKrjnQo_5R\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"98BSgJd4PR\",\"type\":\"code\",\"data\":{\"code\":\"console.log(username);\\nvar username = \\\"Alex\\\";\\n\"}},{\"id\":\"Ks_itvqOez\",\"type\":\"paragraph\",\"data\":{\"text\":\"<i>Block B:<\/i>\"}},{\"id\":\"a1TuVfmtba\",\"type\":\"paragraph\",\"data\":{\"text\":\"JavaScript\"}},{\"id\":\"UhGV5b1c-j\",\"type\":\"code\",\"data\":{\"code\":\"console.log(adminName);\\nlet adminName = \\\"Sarah\\\";\\n\"}},{\"id\":\"Tf1ofFicCa\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>How to Answer:<\/b>\"}},{\"id\":\"uKrYvbZIWv\",\"type\":\"paragraph\",\"data\":{\"text\":\"Block A will output <code>undefined<\/code>. Because <code>var<\/code> is hoisted and given a default value of undefined during the memory phase, the code does not crash.\"}},{\"id\":\"PG5EMe35Ao\",\"type\":\"paragraph\",\"data\":{\"text\":\"Block B will throw a <code>ReferenceError<\/code>. Even though <code>let<\/code> is hoisted, it is caught in the Temporal Dead Zone. The engine knows <code>adminName<\/code> exists in the memory space, but strictly forbids you from touching it until the initialization line is executed.\"}},{\"id\":\"imJuHMAllh\",\"type\":\"header\",\"data\":{\"text\":\"Interview Question 3: Why should we stop using <code>var<\/code> entirely?\",\"level\":3}},{\"id\":\"Yq3lYLT5L5\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>How to Answer:<\/b>\"}},{\"id\":\"HyDG8KO_dK\",\"type\":\"paragraph\",\"data\":{\"text\":\"\\\"Using <code>var<\/code> introduces unpredictability into the codebase. Because it ignores block scope, it increases the risk of variable leaking and accidental overwriting, especially in large, complex applications. It also masks errors by returning <code>undefined<\/code> when hoisted, rather than throwing a hard error like <code>let<\/code> or <code>const<\/code> do via the Temporal Dead Zone. By sticking to <code>const<\/code> for immutability and <code>let<\/code> for variables that must change, we write predictable, safer, and cleaner code.\\\"\"}},{\"id\":\"LnN4g_bBHi\",\"type\":\"header\",\"data\":{\"text\":\"Final Thoughts for Your Interview\",\"level\":2}},{\"id\":\"BI-2UN_XZt\",\"type\":\"paragraph\",\"data\":{\"text\":\"When you are sitting in that interview chair, remember that coding is not just about making things work; it is about writing predictable, maintainable software.\"}},{\"id\":\"42IkOasib6\",\"type\":\"paragraph\",\"data\":{\"text\":\"By understanding the deep mechanics behind <code>var<\/code>, <code>let<\/code>, and <code>const<\/code>, you are proving to the interviewer that you do not just memorize syntax. You are showing them that you understand the JavaScript engine, memory allocation, and the historical context of ECMAScript updates.\"}},{\"id\":\"_3ZlvZudKT\",\"type\":\"embed\",\"data\":{\"service\":\"youtube\",\"source\":\"https:\/\/youtu.be\/s0tZoAGmcYU?si=9IxcXKeraAMfGGIJ\",\"embed\":\"https:\/\/www.youtube.com\/embed\/s0tZoAGmcYU?\",\"width\":580,\"height\":320,\"caption\":\"\"}},{\"id\":\"g1CvrCf3rv\",\"type\":\"paragraph\",\"data\":{\"text\":\"<b>A golden rule of thumb to take away:<\/b> Always default to <code>const<\/code>. If you realize later that the variable needs to be updated (like a counter in a loop), change it to <code>let<\/code>. And as for <code>var<\/code>? Leave it in the past where it belongs.\"}},{\"id\":\"sLOLYrtzwh\",\"type\":\"paragraph\",\"data\":{\"text\":\"Happy coding, and good luck on your next JavaScript interview!\"}}],\"version\":\"2.30.6\"}","thumbnail":"seo\/difference-between-var-let-and-const-in-javascript-interview-guide-1786197939.jfif","status":"published","excerpt":"Master the difference between var, let, and const in JavaScript. Learn about scope, hoisting, and the Temporal Dead Zone (TDZ) with real-world examples and interview questions.","published_at":"2026-08-08T14:05:38.254000Z","tags":"[\"web-development\",\"react-js\",\"javascript\",\"frontend\",\"frontend-development\",\"web-development-tutorial\"]","created_at":"2026-08-08T14:05:39.000000Z","updated_at":"2026-11-23T17:23:45.000000Z","views":43,"scheduled_at":null,"score":1786198025}],"categories":[{"id":2,"name":"Web Development","slug":"web-development","created_at":"2026-07-05T12:39:07.000000Z","updated_at":"2026-07-05T12:39:07.000000Z","blogs_count":12},{"id":3,"name":"Programing Language","slug":"programing-language","created_at":"2026-07-05T12:39:37.000000Z","updated_at":"2026-07-05T12:39:37.000000Z","blogs_count":1}],"tags":{"web development":7,"javascript":6,"JavaScript":5,"frontend":5,"react js":5,"React":4,"Frontend":4,"html":4,"react":4,"ReactJS":2,"React Tutorial":2,"css":2,"react native":2,"web-development":2,"frontend-development":2,"web-development-tutorial":2,"Vite":1,"Webpack":1,"Import Error":1,"Module Not Found":1,"React Hooks":1,"useEffect":1,"React Errors":1,"React Debugging":1,"php chat application tutorial":1,"php":1,"website":1,"web project":1,"chat application":1,"vanilla javascript fetch api project":1,"backend":1,"full stack developer":1,"node js":1,"express js":1,"otp":1,"how to build":1,"node js email otp verification":1,"vite":1,"ReactJs":1,"google":1,"google project":1,"Class Components":1,"LocalStorage":1,"Frontend Development":1,"Google Keep Clone":1,"Web Development Tutorial":1,"React Js":1,"stripe sdk crash react native":1,"stripe":1,"stripe react":1,"android":1,"ios":1,"deploy react native":1,"app to play store":1,"hooks":1,"android development":1,"ios development":1,"react native developer":1,"react-js":1,"JavaScript Arrays":1,"Array Methods":1,"JavaScript Tutorial":1,"Web Development":1,"Programming":1,"js":1,"add to cart":1,"filter":1,"e-commerce":1}}