🚀 Day 15:– JavaScript + DSA (Java) I learned: 🌐 Global Object & globalThis The Global Object is like a library containing all functions and variables accessible globally. In browsers, it’s window; in Node.js, it’s global. globalThis gives a uniform reference to the global object across environments. Inside functions, this behaves differently based on mode: Non-strict mode: this → global object Strict mode: this → undefined 🔹 Inside Objects & Methods this refers to the object that owns the method: const obj = { name: "Kaushal", greet: function() { console.log(this.name); // Kaushal } } obj.greet(); Arrow functions don’t have their own this, they inherit from the surrounding scope. 🔹 Constructors & Classes this points to the instance being created: class Person { constructor(name, age) { this.name = name; this.age = age; } } let a = new Person("Kaushal", 20); console.log(a); // Person {name: "Kaushal", age: 20} 💻 Also explored in Java: Generating all binary strings of a given length without consecutive 1s ✅ LeetCode #22-->Attempted balanced parentheses problem →still a work in progress 😅 #JavaScript #Java #LeetCode #CodingJourney #100DaysOfCode #LearningByDoing
Understanding JavaScript's Global Object & this Keyword
More Relevant Posts
-
🚀 Day 22 :- JavaScript + DSA (Java) 💻 JavaScript – Event Listeners I explored how websites respond to user actions using event listeners. Mouse Events click – triggers when a user clicks on an element dblclick – triggers when a user double-clicks on an element mouseover – triggers when the mouse pointer enters an element mousemove – triggers whenever the mouse moves inside an element Keyboard Events keydown – triggers when a key is pressed down keyup – triggers when a key is released Event Object The event object provides information about the interaction happening in the browser: event – the main object created when an event occurs event.target – the element that triggered the event event.type – the type of event that occurred event.key – shows which keyboard key was pressed event.clientX – horizontal mouse position in the viewport event.clientY – vertical mouse position in the viewport 🧠 Java (DSA) Today I learned about Cyclic Sort and solved : LeetCode Problem #268 – Missing Number (using 4 different approaches): 1️⃣ Sorting Approach :- Used built-in sorting and then checked which index didn’t match the value. 2️⃣ Boolean Array Approach : Used an extra boolean array to mark numbers that appear and find the missing one. 3️⃣ Mathematical (Sum) Approach: Applied the formula for the sum of first n numbers and subtracted the array sum. 4️⃣ Optimal Approach (Follow-up Requirement) : Solved it with Time Complexity: O(n) and Space Complexity: O(1). Learning multiple approaches to the same problem really helps strengthen problem-solving skills. #Day22 #JavaScript #DSA #Java #LeetCode #CodingJourney #100DaysOfCode
To view or add a comment, sign in
-
-
While learning JavaScript deeply, I came across a concept that completely changed how I think about variables. In JavaScript, variables don’t have types — values do. Unlike languages like Java or C++, where a variable’s type is fixed, JavaScript variables are just containers that can reference different kinds of values over time. Example: let x = 10; // number x = "hello"; // string x = true; // boolean The variable x stays the same, but the value (and its type) changes. Understanding this simple idea makes many JavaScript behaviors — like dynamic typing and type coercion — much easier to reason about. I wrote a short post explaining this concept clearly. Check it out here: https://lnkd.in/gMZ-ESa3
To view or add a comment, sign in
-
-
𝗗𝗮𝘆 𝟲/𝟵𝟬: 𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗣𝗿𝗼𝘁𝗼𝘁𝘆𝗽𝗲 I dove into why JavaScript is called a Prototype-oriented language. Unlike Java (which uses Classes as blueprints), JS uses Prototypes to share features between objects. What is a Prototype? Every object and function in JS has a hidden property called a Prototype. Think of it as a "Parent" or a "Template" that stores methods and properties for its instances to use. How it works : Instead of giving every single object its own copy of a function (which wastes memory), we add the function to the Constructor's Prototype. var User = function() { }; User.prototype.greet = "Hello World!"; console.log(new User().greet); // Prints: Hello World!
To view or add a comment, sign in
-
Coming from languages like C/C++ or Java, JavaScript can feel a bit like magic. There’s no dedicated, pre-run compiler—everything happens on the fly! So, what actually happens under the hood when a simple JavaScript program runs? 1. The Translation Phase (From Code to Machine Language) Parsing: The engine's parser checks for syntax errors, breaks the code into tokens (keywords, Identifiers, operators, etc.), and builds a tree structure called the Abstract Syntax Tree (AST). Interpretation: The engine translates the AST into Bytecode (an intermediate language) and execution starts immediately using this Bytecode line-by-line. JIT Compilation: As the Bytecode runs, a "Profiler" watches the code. If it notices a specific function is being used over and over again(called "hot" code), it passes that specific bytecode to the JIT Compiler. 2. Where Does Everything Live? (Memory) While the program is loaded into RAM, memory is split into two main areas: The Heap: Stores complex reference types (Objects, Arrays, Functions) and program data. The Stack: Stores primitive values, memory references (addresses), and the Execution Contexts. 3. The Execution Phase (How it Runs) Whenever a JS program runs, a Global Execution Context (GEC) is pushed onto the Call Stack. JS engine is single-threaded, meaning it executes synchronously, line-by-line. The GEC creation happens in two distinct phases: 🧠Memory Creation Phase: The engine scans the code and allocates memory. Functions get their complete bodies stored. Variables declared with var are initialized as undefined, while let and const variables are placed in the Temporary Dead Zone (TDZ). 💻 Code Execution Phase: The engine executes the program top-to-bottom. Whenever a new function is invoked, a brand new Execution Context is created and pushed onto the Call Stack to handle it! Have you ever looked into how your favorite programming language executes under the hood? Let me know in the comments! 👇 #JavaScript #WebDevelopment #CodingJourney #JSEngine #SoftwareEngineering #TechTips#
To view or add a comment, sign in
-
-
Choosing the right language depends on your domain. Web Development HTML CSS JavaScript TypeScript PHP React Angular Python Java SQL Software Development C C++ Java Python C# Swift Kotlin Rust Go Ruby Machine Learning Python R Julia Java C++ Scala MATLAB JavaScript Lisp Prolog There is no "best language." There is only the right language for your goal. #webdevelopment #softwaredevelopment #machinelearning #html #css #js #php #c #c++ #python #scala #pytorch #go #java #angular #sql #ruby #c# #rust #tensorflow #julia #scikitlearn #keras #r #reactjs #kotlin
To view or add a comment, sign in
-
-
Abstraction - Java Script · Abstraction means hiding internal implementation details and showing only the essential features to the user. · In JavaScript, abstraction can be achieved using: · Classes · Private fields (#) · Closures YouTube Link: https://lnkd.in/gwJCZP3K
Abstraction - JavaScript
https://www.youtube.com/
To view or add a comment, sign in
-
I have started a challenge today to finish Javascript in 1 week. #DAY1 ✨ Today I have done these basic questions of Java Script. Print your name, age Create variables and check typeof 1. Print Name & Age let name = "Rahul"; let age = 21; console.log("Name:", name); console.log("Age:", age); Output Name: Rahul Age: 21 2. Check typeof of Variables let name = "Rahul"; let age = 21; let isStudent = true; console.log(typeof name); // string console.log(typeof age); // number console.log(typeof isStudent); // boolean 3. More typeof Examples let x; let y = null; let arr = [1, 2, 3]; let obj = {a: 1}; console.log(typeof x); // undefined console.log(typeof y); // object (important JS bug ⚠️) console.log(typeof arr); // object console.log(typeof obj); // object typeof null = "object" kyun aata hai typeof null = "object" ❓ (Why?) JavaScript let y = null; console.log(typeof y); // object 👉 Expected kya hona chahiye? "null" 👉 But actual output aata hai: "object" 💡 Reason (Simple Explanation) Ye JavaScript ka old bug hai, jo aaj tak fix nahi hua. 🔧 Internal reason: Jab JavaScript banayi gayi (1995 me), us time pe: Values ko binary format me store kiya jata tha Objects ka type code = 0 hota tha null ka representation bhi 0 tha 👉 Isliye: null → object treat ho gaya ❌ ⚠️ Important Point Ye bug hai, feature nahi But ab isse change nahi kar sakte (backward compatibility issue) 🧠 Interview / Exam Line In JavaScript, typeof null returns "object" due to a historical bug in the language, where null was incorrectly classified as an object. ✅ Correct Way to Check null let y = null; if (y === null) { console.log("y is null"); } 👉 Always use: === null #coding #consistency #CS #practice
To view or add a comment, sign in
-
🚀 Day 18:– JavaScript + DSA (Java) Today’s learning was focused on strengthening my understanding of Data Structures & Algorithms and revising JavaScript fundamentals. 🔹Java – Merge Sort I explored the Merge Sort algorithm in depth and understood how it works internally: ->Uses the Divide and Conquer technique. ->Recursively divides the array into smaller subarrays. ->Merges the sorted subarrays to form the final sorted array. ->Time Complexity: O(n log n) in best, average, and worst cases. ->Stable Sorting Algorithm ✅ Not an In-Place Algorithm because it requires extra space during merging. Understanding the step-by-step splitting and merging process helped me clearly see why the time complexity becomes O(n log n). 🔹 JavaScript Revision Also spent time revising core JavaScript concepts to keep my fundamentals strong while continuing my programming journey. #100DaysOfCode #Java #JavaScript #DSA #MergeSort #CodingJourney #LearningInPublic
To view or add a comment, sign in
-
-
10 Claude Code CLI commands worth knowing if you work with Java, React, Node.js, or danfo.js. Not tricks. Actual commands that change the workflow. 1. Reference a specific file in your prompt claude "review @./src/api/UserService.java for null pointer risks" Claude reads it. No copy-paste. 2. Run a shell command without leaving the session !npm test Results come back in context. Claude sees what broke. 3. Non-interactive one-shot execution claude -p "find all unhandled promise rejections in @./src/" Pipe it. Script it. No session needed. 4. Plan before touching code /plan Claude analyzes, proposes. You approve. Nothing changes until you say so. 5. Generate tests for a utility module claude "write Jest tests for @./src/utils/validation.js" TDD cycle gets faster here. 6. Analyze a React component for accessibility gaps claude "review @./src/components/Table.tsx for accessibility issues" One command. Structured output. 7. Refactor for dependency injection claude "refactor @./src/services/EmailService.js to use dependency injection" Works across multiple files if needed. 8. Generate API docs for a route directory claude "generate API docs for all endpoints in @./src/routes/" Useful before a sprint review. 9. Switch model mid-session for cost control Use Haiku for exploration. Switch to Sonnet for output. Heavy codebase scans do not need your most expensive model. 10. Run Claude Code in CI for lint fixes claude -p "fix any linting errors and suggest a commit message" Drop it into GitHub Actions. Let it clean before merge. The @ symbol is underused. Most developers type file names in prose. That is context Claude cannot act on. Direct reference beats description every time. #ClaudeCode #DeveloperProductivity #AIEngineering #EnterpriseArchitecture #JavaDevelopment #ReactJS #NodeJS #SoftwareDevelopment #AICoding #EngineeringLeadership
To view or add a comment, sign in
-
🚀 Java Battle: Static vs. Instance Initializer Blocks 🚀 ✔️Ever wondered who wins the race when a Java class loads? ✔️If you’re prepping for an interview or just cleaning up your codebase, understanding the execution order is a game-changer. 🏗️ The Static Block (static { ... }) 🔸 When: Runs once when the class is first loaded into memory. 🔸Why: Perfect for initializing static variables or configuration that applies to the entire class. 🔸The Catch: It doesn’t care about objects. It runs even if you never call new MyClass(). 🏠 The Instance Block ({ ... }) 🔸 When: Runs every single time you create a new instance (object). 🔸 Why: Great for code that must run regardless of which constructor is called. 🔸 The Secret: It executes right after the super() call and before the rest of the constructor body. 💻 See it in Action public class JavaDemo { static { System.out.println("1. Static Block: I'm the pioneer. I run once."); } { System.out.println("2. Instance Block: I run every time an object is born."); } public JavaDemo() { System.out.println("3. Constructor: I finish the job."); } public static void main(String[] args) { new JavaDemo(); } } 📈 The Output: 🔸 Static Block (Only once!) 🔸 Instance Block (Object 1) 🔸 Constructor (Object 1) 💡 Pro-Tip: ✔️ While Instance Blocks are cool, they are rare in the wild. Most developers prefer putting logic directly in constructors for better readability. ✔️ Static Blocks, however, are your best friends for heavy-duty class-level setup (like loading native libraries). ❓Which one do you use more often in your projects? Let’s talk in the comments! 👇 #Java #Programming #Backend #SoftwareEngineering #CodingTips #JavaDeveloper
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development