menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Javascript

Javascript

source image

Medium

1M

read

439

img
dot

Image Credit: Medium

JavaScript Objects Made Easy: 5 Simple Ways to Create Them

  • JavaScript objects store, manipulate, and send data in a collection of name-value pairs.
  • Objects in JavaScript can be created using curly braces, constructors, Object.create() method, functions as blueprints, or classes.
  • Object.create() method allows creating objects from an existing blueprint to inherit properties and methods without constructors.
  • JavaScript offers various methods like object literals, new Object(), Object.create(), constructor functions, and classes to create objects based on different requirements.

Read Full Article

like

26 Likes

source image

Medium

1M

read

0

img
dot

Image Credit: Medium

The Truth About NaN, Infinity, and -0 in JavaScript

  • JavaScript uses IEEE 754 double-precision floating-point format to handle all numbers, including special values like NaN, Infinity, and -0.
  • NaN represents 'Not a Number' and is a special value in JavaScript, which is not equal to itself and requires check using Number.isNaN().
  • Infinity and -Infinity are produced when numbers go beyond the floating-point limits or lead to undefined results in calculations.
  • JavaScript distinguishes between positive and negative zero, with division resulting in Infinity for divide by zero and -Infinity for divide by -0.
  • Understanding how JavaScript handles special values like NaN, Infinity, and -0 is essential for accurate comparisons and calculations.
  • Object.is() is recommended for comparing values, including NaN and -0, due to its strict identity comparison.
  • Arithmetic operations involving NaN result in NaN, while Infinity follows specific rules in different mathematical scenarios.
  • When working with arrays, includes() is more reliable for NaN comparisons than indexOf() due to handling NaN as equal to itself.
  • Objects, maps, and sets treat special numeric values differently, with Map treating 0 and -0 as the same key.
  • Understanding how JavaScript treats NaN, Infinity, and -0 is crucial for consistent and predictable behavior in programming.

Read Full Article

like

Like

source image

Dev

1M

read

283

img
dot

Image Credit: Dev

Fully agentic coding with OpenAI Codex, JavaScript’s New Superpower, Deno’s updated next-gen web framework, and more

  • OpenAI introduces Codex, an agent that automates coding tasks, enhances productivity, and handles multiple tasks securely, specially designed for JavaScript developers.
  • V8 engine introduces Explicit Resource Management (ERM) for JavaScript resource cleanup, providing more deterministic control over resources.
  • Deno Fresh, a full-stack web framework built for speed and simplicity, receives a major update with V2, including a new build system, improved developer experience, and plugin architecture.
  • Node.js releases critical security updates for multiple versions, addressing cryptographic issues, HTTP header bugs, and memory leaks to ensure secure data handling.
  • Some other notable updates include diff v8.0.1 for text diffing, React Aria Components v1.3 for enhanced accessibility, UnJS Nitro v2.9 with better TypeScript support, and Tamagui v1.126.13 for improved UI performance.

Read Full Article

like

17 Likes

source image

Dev

1M

read

409

img
dot

Image Credit: Dev

block-inspect: A Lightweight JavaScript Utility to Deter Inspect Elements & Protect Your Website Content

  • block-inspect is a new npm package designed to deter users from accessing browser developer tools, disabling right-click context menus, and preventing copy/paste or text selection on websites.
  • It is a lightweight and dependency-free JavaScript utility that offers customizable options for blocking various actions, improving content protection.
  • block-inspect can be easily integrated with one import and function call, making it highly customizable and suitable for sites where casual copying or tampering is a concern.
  • For more details, demo, and documentation, check out the GitHub repository at https://github.com/mahmud-r-farhan. Users can also install block-inspect from npm for their projects.

Read Full Article

like

24 Likes

source image

Dev

1M

read

71

img
dot

Image Credit: Dev

Daily JavaScript Challenge #JS-182: Find the Smallest Positive Integer Not in Array

  • Daily JavaScript Challenge: Find the Smallest Positive Integer Not in Array
  • Given an array of integers, find the smallest positive integer missing from the array.
  • Challenge difficulty: Medium, Topic: Array Manipulation.
  • Join the discussion on approaches, edge cases, and learnings on this challenge.

Read Full Article

like

4 Likes

source image

Dev

1M

read

152

img
dot

Image Credit: Dev

Enable or Disable console.log Globally in JavaScript

  • During development or debugging, you may need to enable or disable logging globally in a JavaScript application.
  • To achieve this, store the original console.log function and create a control function that toggles logging on and off.
  • By setting logging_enabled to true or false, you can control whether console.log behaves as usual or becomes an empty function.
  • This method provides global control over logging, allowing you to keep the console clean and prevent unnecessary clutter during debugging.

Read Full Article

like

9 Likes

source image

Dev

1M

read

359

img
dot

Image Credit: Dev

Clean & Scalable Error Handling in JavaScript: How to Manage Async Errors Without Try-Catch

  • Handling async errors in JavaScript often turns into a mess of try-catch blocks, making the code cluttered and hard to scale as the project grows.
  • Lovit is a library designed to manage async errors in a cleaner and more scalable way, keeping the error handling logic separate from the main functions.
  • The traditional approach involves using try-catch blocks within functions like fetching data from an API, which can become harder to maintain with added complexity.
  • Using Lovit, error handling is separated and defined in a structured manner using functions like createProfile, making it easier to manage errors specific to different parts of an application.

Read Full Article

like

21 Likes

source image

Dev

1M

read

382

img
dot

Image Credit: Dev

Scroll Animation Without JavaScript: Introducing animation-timeline: view();

  • Adding scroll-based animations to your website no longer requires JavaScript with the introduction of animation-timeline: view();, a CSS property.
  • The animation-timeline: view(); property allows CSS animations to be triggered based on the element's scroll position in the viewport.
  • You can define the animation's start and end points in relation to the element's position in the viewport using the animation-range property.
  • animation-timeline: view(); offers a JavaScript-free, cleaner, performant, and easier-to-maintain solution for scroll-triggered animations, suitable for various effects like hero text animations and section reveals.

Read Full Article

like

23 Likes

source image

Dev

1M

read

306

img
dot

Image Credit: Dev

Difference between HTML, CSS and JavaScript in Frontend Development 💻⚙️🚀

  • HTML, CSS, and JavaScript are essential concepts in Frontend development.
  • HTML is used to create webpage structures, CSS is for styling, and JavaScript adds interactivity.
  • Learning these technologies is crucial for beginners in Frontend development.
  • Together, HTML, CSS, and JavaScript help in building complete and interactive websites.

Read Full Article

like

18 Likes

source image

Dev

1M

read

375

img
dot

Image Credit: Dev

Creating Modal Windows with Pure CSS: No JavaScript Required

  • You can create modal windows without JavaScript using only HTML and CSS.
  • This tutorial explores leveraging CSS techniques like the :target pseudo-class and the "checkbox hack" for creating modals.
  • Modal windows traditionally require JavaScript for triggering, hiding, and managing interactions.
  • The :target pseudo-class changes styles based on navigation state, allowing for showing and hiding modals.
  • The checkbox hack uses a hidden checkbox and :checked pseudo-class to toggle modal states.
  • CSS properties like opacity, pointer-events, z-index, and transitions are essential for creating CSS-only modals.
  • An example of building a basic CSS modal using the :target approach is provided with HTML and CSS code snippets.
  • Another method discussed is the checkbox hack alternative for creating modals without changing URL and browser history.
  • Enhancing modals with animations like slide-in and fade-and-scale effects can improve user experience.
  • Considerations for modal responsiveness and accessibility are highlighted for better user interaction.

Read Full Article

like

22 Likes

source image

Dev

1M

read

112

img
dot

Image Credit: Dev

Daily JavaScript Challenge #JS-181: Find the Smallest Missing Positive Integer

  • The challenge focuses on finding the smallest missing positive integer in an unsorted array of integers.
  • Participants are encouraged to write a function that returns the missing integer and test it against provided test cases.
  • For more information, developers can refer to the Wikipedia page on the Pigeonhole Principle.
  • Join the discussion by sharing your approach, interesting edge cases, and key learnings from this challenge in the comments.

Read Full Article

like

6 Likes

source image

Dev

1M

read

153

img
dot

Image Credit: Dev

JavaScript Static vs Private: Explained by My Cat Oreo

  • Regular Variables/Methods: Oreo's name and color are accessible to everyone.
  • Static Variables/Methods: Oreo does not know about the totalCatCount or whatAreCats() as they are both static, so it is only known by the Cat class.
  • Private Variables/Methods: Oreo's energy level and recoverEnergy() are hidden (private) and can only be accessed using a public method, play().
  • Private Static Variables/Methods: Despite being static, the Cat class can't access the #totalCatNaps or #incrementNapCount(), since they are private static.

Read Full Article

like

9 Likes

source image

Medium

1M

read

436

img
dot

Image Credit: Medium

Mechanics Behind Async Iterators and For-Await-Of in JavaScript

  • JavaScript treats asynchronous values and iterable behavior as separate until used with for-await-of loop, where they come together.
  • An object is iterable when it has a method tied to Symbol.iterator that returns an object with a .next() method.
  • Async iterators are similar, but the .next() method returns a Promise, making the loop wait for Promise resolution.
  • for-await-of loop uses Symbol.asyncIterator to handle Promises and values with done flags.
  • Async generators combine yielding values like regular generators with waiting on Promises, allowing for pausing and waiting during execution.
  • The for-await-of loop waits for each yield from an async generator, allowing values to be processed as they arrive.
  • JavaScript engine turns async generators into paused state machines, enabling natural pause and resume functionality without manual handling.
  • Code within the for-await-of loop is paused using microtasks while waiting for Promises, ensuring asynchronous loops remain responsive.
  • for-await-of loop throws exceptions for rejected Promises, and the entire loop structure should be inside a try block to catch errors.
  • If a loop exits early, the engine checks for a .return() method in the iterator to clean up resources before finishing.

Read Full Article

like

26 Likes

source image

Dev

1M

read

337

img
dot

Image Credit: Dev

How to Build a White Screen Tool with HTML, CSS, and JavaScript

  • A white screen tool is a utility that turns your browser into a blank, fullscreen white canvas, used by photographers, developers, and for reducing distractions.
  • In this tutorial, learn how to build a white screen tool using HTML, CSS, and JavaScript without any libraries or frameworks.
  • Create the HTML structure with a button to trigger white screen mode and include script and stylesheet links.
  • Enhance the page with CSS styling for the button and setting up a class to turn the background white when activated, along with adding JavaScript to enable fullscreen white mode.

Read Full Article

like

20 Likes

source image

Dev

1M

read

369

img
dot

Image Credit: Dev

How The JavaScript Event Loop Handles Asynchronous Code Execution

  • JavaScript event loop enables asynchronous code execution in a single-threaded environment by managing tasks using call stack, Web APIs, Task Queue, and Microtask Queue.
  • Call Stack: Functions are pushed and popped for execution, one at a time.
  • Web APIs/Node APIs: Provided by the browser or Node.js for async operations like setTimeout, fetch, DOM events, running outside the main thread.
  • Event Loop: Checks Call Stack first, then Microtask Queue, and Task Queue for handling async tasks continuously, ensuring smooth and responsive application behavior.

Read Full Article

like

22 Likes

For uninterrupted reading, download the app