JavaScript: NaN
Some operations with infinity, for example, dividing infinity by infinity, return a weird result. In math, this operation has no numerical equivalent. In JavaScript, you'll get NaN.
Infinity / Infinity; // NaNNaN is a special value, "not a number", that usually indicates execution of a meaningless operation. Any operation with NaN returns NaN.
NaN + 1; // NaNNaN is a peculiar value. Although it means "not a number", it belongs to the number data type. What a paradox. NaN is never a value you want to see, it appears only as a result of errors. If you come across it, find the point where the operation that wasn't valid for numbers was performed, and correct the piece of code.
Instructions
Execute the operation that returns NaN and print it using console.log().
Tips
If you've reached a deadlock it's time to ask your question in the «Discussions». How ask a question correctly:
- Be sure to attach the test output, without it it's almost impossible to figure out what went wrong, even if you show your code. It's complicated for developers to execute code in their heads, but having a mistake before their eyes most probably will be helpful.
Your exercise will be checked with these tests:
// @ts-check
import { expect, test, vi } from 'vitest';
test('nan', async () => {
const consoleLogSpy = vi.spyOn(console, 'log');
await import('./index.js');
const firstArg = consoleLogSpy.mock.calls.join('\n');
expect(firstArg).toBe('NaN');
});Teacher's solution will be available in:
20:00
