

For a number, the max value that we can have comes out to bee 1.7976931348623157e+308. If you move to the console with this file, the output as you can find would be a number, for both the above-created variables. You can verify it using the type of operator. So, for the above 2 variables that we have created, the values are numbers, so a type is also a number. So, depending upon what value are we giving, the type will be decided. We are just creating some variables, and assigning some value to them. We are already familiar with how can we create variables. Now, let’s have an explanation for the above-written lines. Since majorly, we are going to deal with JavaScript here, we would be writing our JavaScript into a JavaScript file. Other than that, the HTML file is already created and we have given this JavaScript file as the source for that HTML file.
#Basic data types in javascript code
Well, the above code is just some JavaScript. Have a look at the below program, and after that, we will have a brief explanation about it as well. Let’s first have a look at storing number data to the variable. There are some other things like objects, which we are going to discuss as we move forward.Īlso, we are going to see an operator, which is a type of, use in which, we are going to get the type of data that we are using.įirst of all, understand that there are different types of data that we are dealing with. You can convert a value of any other data type to a boolean data type using the Boolean() function.These are all kinds of Primitive data types(basic data types). Boolean values are the result of logical comparisons. The boolean data type can have two values: true and false. Infinity and -Infinity: Infinity and -Infinity represents the mathematical ∞ and -∞ respectively.console.log( NaN = NaN) įalse Also, if a mathematical expression somewhere contains NaN, the result is always NaN. console.log( "MakeUseOf"/ 10) Output: NaN Interestingly enough, NaN is not equal to anything, including itself. For example, if you divide a string and a number, the result will be NaN. NaN: NaN stands for Not a Number which means an invalid number.JavaScript also provides other special numeric values that belong to the number data type-NaN, Infinity, and -Infinity.

You can use e-notation to represent very large or very small numbers. The following statement creates a variable holding a floating-point number: let x = 324.56 Similarly, if you want to create hexadecimal (base 16) literals, use the 0x prefix with the sequence of hexadecimal digits(0 to 9, and A to F). If you want to create octal (base 8) literals, you need to use the 0o prefix with the sequence of octal digits (digits from 0 to 7). The following statement creates a variable holding an integer: let x = 21

Some examples to create numbers in JavaScript: // Using literal declaration To perform more complex operations, you can use the built-in Math object. You can perform many operations on numbers in JavaScript like addition, subtraction, division, multiplication, and so on. The number data type in JavaScript uses the IEEE-754 format to represent both integer and floating-point numbers.
