FAQ: Introduction to JavaScript - Data Types

What is the difference between the primitive data type “number” and the Object Number:

If you’re on windows, press the ‘Insert’ key

Check the domain name in the location bar.

@ namibianwolf
these threads are the best, just had this same question and glad to feel like I am not the only one to misunderstand the exercise here

Hi! whats the difference between null and undefined? Can someone give me an example? Thanks!

Images are worth a thousand words:

image
image

3 Likes

:rofl: Perfect explanation! Thanks!

Shouldn’t the console.log response from line 1 and line 2 be in different colors, as one is a string, and one is a number?

the first rule of every programmer is to read the syntax.
The syntax for strings in JS says you must use the quotation marks when the data type is strings. This helps Javascript to differentiate between strings and other data types, eg Num.

let x = 5 + 5; //outputs 10
let y = “5 + 5”; //outputs 5+5

this way, you can have the option to print out the second variable (y=5+5) if you want individual numbers to be printed and you don’t want to sum it unlike the first variable.

Is just a way for javascript to interprets what type of data you want


What’s wrong with this picture?

There are 8 data types listed, and it’s unclear as to whether Symbol is a fundamental datatype consequently.

1 Like

I came here to ask the exact same question! :laughing:

The answer

The “Number” object comes with several methods, such as toFixed() , toPrecision() , and toString() , which are not available on primitive numbers directly.

let primitiveNumber = 42;
let numberObject = new Number(42);

console.log(primitiveNumber.toFixed(2));  // Error: toFixed is not a function
console.log(numberObject.toFixed(2));     // Outputs: "42.00"

While you can use primitive “number” values in most situations, there are scenarios where using the “Number” object might be necessary. For example, when working with functions that expect objects rather than primitive values, or when you need to access additional methods provided by the “Number” object.

In the excercise it talked about for a BigINT you append a “n” to the end of the number. Why do you have to append “n” to the end of the number?

like this:
42 is a number
42n is a bigint

1 Like

Oh okay, so it’s basically the syntax way to denote that it is of data type: bigint…whereas the data type: “number” can be either an integer or a float/double/decimal number. I have experience with Java and Python, I think both of those you have to identify integers and decimal numbers differently. It has been awhile, though.

Thank you for your reply :slight_smile: