The significance of order when evaluating 2 Date Objects

While working with Date objects, I encountered something peculiar. When comparing two Date objects - let's call them a and b, the expressions a > b and b < a yield different results.

Check out this JSFiddle for an example.

var u = Date(2014,7,5,14,00);
var k = Date(2014,7,5,13,50);
alert(" this is " + k<u);
alert(" this is " + u>k);

I'm trying to figure out what I might be missing here. Any insights?

Answer №1

You seem to be facing an issue with operator precedence.

alert(" this is " + k<u)

can easily be confused with

alert((" this is "+k) < u)

rather than

alert(" this is " + (k<u))

which is what you actually want to achieve.

Just remember to include the parentheses for it to function correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting Loading Problems in React Native Using Geny Motion

Currently utilizing react native Using react-native-cli version 2.0.1 and react-native version 0.55.3 Execution was done through react-native run-android Encountering a perpetual loading screen while running the app in debugger mode, with 127.0.0.1:8081 ...

Utilizing web components from NPM packages in conjunction with Svelte

My current project involves the development of a simple Single Page App (SPA) using Svelte. I have successfully implemented a basic layout and styling, as well as an asynchronous web request triggered by a button click. Now, my next objective is to utiliz ...

Could one potentially use jQuery to navigate through JSON output?

My goal is to generate a JSON list that includes CSS classes and their respective URL records. Here's an example: var jsonList = [{ "CSSClass": "testclass1", "VideoUrl": "/Movies/movie.flv" }, { "CSSClass": "testclass2", "VideoUrl": "/Movies/ ...

Utilizing a form of delegation design in JavaScript

My goal is to pass data from class A to class B after receiving a message from sockets. Here's a simplified overview of how the classes are defined: In class A: export default class A { client; callbacks; constructor() { this.callbacks = ...

Encounter the "Error: Source 'cloudsTileLayer-RasterSource' not found" message while trying to integrate a weather tile layer into Azure Maps

I have been working on a React application that utilizes the React-Azure-Maps npm package. My current challenge involves creating a weather layer, which I believe shares similarities with the sample code provided for layers. The code snippet responsible f ...

What is the reason behind the inability to send an object from the parent component to a child component within a Vue 3 application?

I've encountered an issue while working on a Vue 3 app involving a component and its <User /> subcomponent. Within App.vue: <template> <Navbar /> <Sidebar /> <Content title="Users" /> <Footer ...

How can we use the useState hook in React to dynamically generate state variables?

I'm currently working on a React app where input fields need to be stored in the state. While I can use the useState hook to easily store these values, the challenge I'm facing is that I don't know what fields are needed since they are retri ...

Trigger the function upon displaying the modal

Within my Bootstrap project, I have set up a click event to trigger a modal as follows: $('#make_selects_modal').appendTo("body").modal('show'); My requirement is to run a function called pickClient when this modal is displayed. I att ...

What are some strategies for optimizing Next.js applications for mobile devices?

https://i.stack.imgur.com/mWmWG.png After realizing that the structure of my Next.js app doesn't align with Create React App's folder system, I'm stuck on how to effectively scale my website for mobile devices. In my confusion, I'm una ...

Create dynamic elements within bootstrap-vue using data from a JSON file

Currently, I am utilizing BootstrapVue (Bootstrap 4.6 and VueJS 2)! My objective is to dynamically generate elements such as input fields, dropdowns, and checkboxes based on a JSON file structured like so: [ { "unique_number": "1111", "key": ...

TypeScript Compile Error: The property is not available in the 'IStateParamsService' type

My client project heavily utilizes TypeScript. Currently, I am encountering a technical issue. Within my HTML code, I have an anchor tag as shown below: <a class="btn btn-default mrm" ui-sref="course-detail({courseId: '{{c.Id}}'})">Detail ...

Tips for Choosing the Right Objects in Vue.js

I have the following code that combines all objects in a person and stores them in an array called Cash:[] this.cash = person.userinvoice.concat(person.usercashfloat) Inside person.usercashfloat, there is an element called validate which sometimes equals ...

"Ways to retrieve an array of dates within a specified range of date and time

I am working with date fields in my project { tripScheduleStartDate: '2018-12-05T18:30:00.000Z', tripScheduleEndDate: '2018-12-07T18:30:00.000Z', } Is there a way to generate a datetime array from the start date to the end date, lik ...

Adjust the height of the container to accommodate responsive images automatically

Hello, I am trying to make the container height adjust automatically based on the responsive image it contains. The container's display is set to flex and the image is positioned between two divs with the class "text-block". These divs have a width of ...

Issues with jQuery .click and .html functions not functioning as expected

Does anyone have experience creating a game with jQuery? I can't seem to get the options after the first choice to work. Sorry, I don't have a working example at the moment. --- jQuery --- $(document).ready(function() { $(".console"). ...

Achieve this effect by making sure that when a user scrolls on their browser, 50% of the content is entered into view and the remaining 50%

Is there a way to achieve this effect? Specifically, when the user scrolls in the browser, 50% of the content is displayed at the top and the other 50% is shown at the bottom. ...

PHP script failing to execute if/else statement during AJAX request

I am currently developing a website that heavily relies on Ajax, and I have chosen to use codeigniter for its construction. On the site, there is a form with the post method, and this form is submitted using an Ajax request that calls a function containi ...

Customizing Ext JS/Sencha Chart framework based on certain conditions

As someone who is new to Ext JS and Sencha charts, I have encountered a challenge with one of the charts in our application. Specifically, I needed to hide the dashes on the X-Axis of that particular chart. Our application is built using Ext JS version 5.1 ...

The loading of Google maps occurs simultaneously with ongoing AJAX requests

I am currently working with the Google Maps API in combination with rails 5.0.4. My goal is to have the map center on the user's location and populate the latitude and longitude fields with the corresponding coordinates. Right now, the lat, lng field ...

Ways to eliminate the occurrence of 'undefined' in Object.keys while using forEach loop

Hey there! I'm currently working with Node.js and running into an issue with using forEach on Object.keys. In the code snippet below, when I try to execute it, I encounter a problem where the first value in the output is undefined. For instance, let&a ...