Learn Programming Fundamentals
1 Programming Fundamentals
3 Conditional Structures
4 Strings
5 Arrays
6 Objects
8 Functions
Data types are essential in programming as they determine the nature of data stored and manipulated within a program. In JavaScript, variables can hold values of different types.
For example:
var x = 19 + "Henry";
In this case, x
is assigned the value "19Henry"
. JavaScript performs type conversion, concatenating the string "Henry"
with the number 19
.
In contrast:
var x = 19 + 20;
Here, x
is assigned the value 39
, as JavaScript correctly performs arithmetic addition with two numbers.
All programming languages support several main data types:
true
or false
.Understanding data types is crucial as they govern how data is handled within a program, ensuring accurate processing and manipulation.
In JavaScript, we have numbers, booleans, and strings. JavaScript is a dynamically-typed language, meaning variables are not bound to a specific data type and can hold values of any type.
For example:
let x = 90; // Number let floatValue = 20.38; // Number let text = "This is a string"; // String let hasPhone = true; // Boolean