A data type is an attribute of data which tells the compiler or interpreter how the programmer intends to use the data. It defines what kind of value a variable can hold, what operations can be performed on that value, and how the data is stored in memory.
Common data types in programming include integers, floating-point numbers, strings, boolean values, arrays, and objects, among others.
Understanding data types is important in programming as it helps ensure that the program operates as expected, and it can also impact performance and memory usage.
<!DOCTYPE html>
<html>
<head>
<script src="main.js"></script>
</head>
<body>
<script>
var x = 234234;
var y = 23423.23;
var z = -234232.234523;
var c = "A";
var s = "klkjhljksdahf jkhas dlfkjh";
document.write(x);
document.write("<br>");
document.write(y);
document.write("<br>");
document.write(z);
document.write("<br>");
document.write(c);
document.write("<br>");
document.write(s);
document.write("<br>");
</script>
</body>
</html>
This JavaScript code declares and initializes variables of different data types and then uses the document.write()
method to display their values.
The variables and their values are:
x
is an integer with the value of234234
.y
is a floating-point number with the value of23423.23
.z
is a negative floating-point number with the value of-234232.234523
.c
is a string containing a single characterA
.s
is a string containing a sequence of charactersklkjhljksdahf jkhas dlfkjh
.
The code prints each variable's value on a new line by using the document.write()
method and HTML line break tag <br>
.
An integer is a whole number, meaning it doesn't have any decimal or fractional part. Examples of integers are 0, 1, -10, 100, etc.
A float, or a floating-point number, is a number that has a decimal point, allowing for fractional values. Examples of floats are 1.2, -3.14159, 6.66, etc.
A string is a sequence of characters, such as letters, numbers, and symbols, enclosed in quotation marks. Examples of strings are "hello world", "123", "John Smith", etc.
No comments:
Post a Comment