When JavaScript adds a number to a Date object with the + operator, it converts the date to text and appends the number. The result shows the current date and time followed by 10—not a date ten days later. For date arithmetic, use methods such as setDate() or work with timestamps.

Multiple Choice

Given the code: const myDt = new Date(); console.log(myDt + 10); what will be the output?

The output of the code is determined by how JavaScript handles the addition of a number to a Date object when the `+` operator is used. In JavaScript, when you attempt to concatenate a Date object with a number using the `+` operator, the Date object is first converted to a string representation of the date. When the code `console.log(myDt + 10);` is executed, the Date object `myDt` is converted to a string that represents the current date and time. Then, the `10` is treated as a string and concatenated to this date string. As a result, the output will not represent a date calculation, such as adding 10 days, but rather it will simply show the string representation of the date followed by the number `10`. Therefore, given how JavaScript handles the addition of a Date object and a number, the output would actually be a string containing the current date and time with `10` appended to it. The provided answer of "Today's date, plus 10 days" does not accurately reflect this behavior. The correct interpretation of the output focuses on the string concatenation rather than any date arithmetic.

A JavaScript Date can look like a number, but it isn’t one. That small distinction matters when you use the + operator. Given a current date stored in myDt, this line—


const myDt = new Date();

console.log(myDt + 10);


—prints the date and time as a string, followed by `10`. It does **not** add ten days, and it does not simply produce a millisecond value. The reason comes down to how JavaScript converts values before combining them.

## The `+` operator has two jobs

Most operators have a single main role. The `+` operator is less predictable because it can add numbers or join strings. JavaScript first converts the values it receives, then decides which behavior to use.

A `Date` object has a special rule during this conversion. When used with `+`, it is generally converted to a human-readable string. The number `10` is then converted to a string too, and the two strings are joined.

So the result is conceptually similar to:

```js

"Mon Nov 16 2026 12:00:00 GMT..." + "10"

The exact date and time depend on when the code runs and the environment where it runs. The result might look like this:


Mon Nov 16 2026 12:00:00 GMT-0800 (Pacific Standard Time)10

That example is only illustrative; the displayed date, time, and time zone can vary. The important point is that 10 appears at the end of the date string. JavaScript hasn’t changed the date at all.

Why it doesn’t mean ten days later

People often read date + 10 as “move this date forward by ten days.” That would be a reasonable meaning in everyday conversation, but JavaScript doesn’t infer units from the value. The number 10 carries no built-in label saying “days.”

There’s another common assumption: since dates can be represented as timestamps, adding a number might add milliseconds. But that’s not what happens here either. The + operator’s conversion rules lead to string concatenation for this expression.

To see the numeric form of a date, ask for it explicitly:


const myDt = new Date();

console.log(myDt.getTime());

getTime() returns the number of milliseconds since January 1, 1970, UTC. Now the value is a number, so adding 10 adds ten milliseconds:


console.log(myDt.getTime() + 10);

That result is a timestamp ten milliseconds later—not ten days later. Ten milliseconds is tiny, of course, but the example makes the units clear.

Adding days requires a clear instruction

For calendar-day arithmetic, use date methods rather than relying on +. One straightforward approach is to make a copy and change its day:


const myDt = new Date();

const tenDaysLater = new Date(myDt);

tenDaysLater.setDate(tenDaysLater.getDate() + 10);

console.log(tenDaysLater);

setDate() updates the day of the month. If that pushes the date past the end of a month, JavaScript rolls the date into the next month. For instance, adding ten days to a date near the end of April will move into May.

Making a copy is useful because setDate() changes the Date object it’s called on. Without the copy, code elsewhere that uses myDt would see the modified date too. That kind of hidden change can be confusing, especially in a Salesforce Lightning Web Component where several parts of the interface may rely on the same value.

There’s a subtle wrinkle: calendar days and fixed blocks of 24 hours aren’t always identical. Daylight saving time can shift the local clock forward or back. If an application means “the same local time ten calendar days later,” methods like setDate() are usually a better fit. If it means “exactly 240 hours later,” timestamp arithmetic may be more suitable:


const tenDaysInMilliseconds = 10 * 24 * 60 * 60 * 1000;

const tenFixedDaysLater = new Date(

myDt.getTime() + tenDaysInMilliseconds

);

Those two approaches can differ around daylight-saving changes. It’s a small detail with real consequences for deadlines, appointments, and billing windows.

A quick way to check what JavaScript sees

When a value behaves unexpectedly, inspect its type and its conversion directly:


console.log(typeof myDt);       // "object"

console.log(String(myDt));      // Human-readable date string

console.log(Number(myDt));      // Timestamp in milliseconds

A Date object is an object, even though JavaScript can convert it to either a string or a number. Different operations can trigger different conversions. That’s why explicit methods are clearer than hoping an operator will guess what you mean.

For example, subtraction between dates often produces a number:


const start = new Date("2026-11-01T00:00:00Z");

const end = new Date("2026-11-11T00:00:00Z");

console.log(end - start);

Subtraction converts both dates to numeric timestamps, so the result is a difference in milliseconds. Addition behaves differently because + also supports string joining. That mismatch can feel odd at first, but it follows JavaScript’s rules.

Keep date handling clear in Salesforce code

Salesforce JavaScript often moves dates between the browser, Lightning components, and server-side Apex. Each layer can introduce questions about formats, time zones, and whether a value represents a date alone or a specific moment.

A JavaScript Date represents a moment in time. By contrast, a business field such as a due date may mean a calendar day, with no meaningful hour or minute. Mixing those ideas can cause dates to appear shifted when they’re serialized, displayed, or interpreted in another time zone.

For example, an ISO timestamp such as "2026-11-16T18:30:00.000Z" includes a time and the Z marker for UTC. A date-only string such as "2026-11-16" carries a different kind of information. Before changing or displaying a value, be clear about which one the application needs.

This is also why a readable display and a reliable calculation are separate concerns. Use Intl.DateTimeFormat when you want to show a date in a chosen locale, and use date or timestamp methods when you need to calculate. Don’t use the output of Date.toString() as a data format; it’s intended for display and can vary by environment.

The key takeaway is simple: myDt + 10 turns the date into text and appends 10. It does not add ten days or ten milliseconds. When working with dates, make the unit and intent explicit—calendar days, elapsed hours, or a formatted label—so the code says exactly what it means.