+ 1

Plz help!! what is data types???

8th Aug 2016, 2:54 PM
hamza hafeez
hamza hafeez - avatar
3 Answers
+ 5
I'm not certain exactly what you are asking, so you may get more information than you hoped for. A data type is exactly what it sounds like - the type of data you are working with. Many Javascript functions involve using data inputted by you or a user. In order for JavaScript to know what to do, it needs to know what type of data it is dealing with. For example, a string is a data type that involves a series of numbers, letters, symbols, or a combination of the three. You signify a string by putting apostrophes or quotation marks around your data - if I were to enter a variable with a value of 'orange' or "orange", the apostrophes/quotation marks would let Javascript know that this was a string data type, and it could deal with it accordingly. A number is a data type that is, simply, a number. Unlike a string, a number does not need apostrophes or quotation marks. While you can enter a number into a string (ie. '354'), Javascript would treat it as a string, so if you tried to add '354' + '1', Javascript would give you '3541' because it treats it just like it would if it was adding strings together. However, if you added 354 + 1 without the apostrophes or quotation marks, Javascript would add it up to 355 because it can add the number data type. This is an example of when data type is important. A boolean is a data type with a value of either true or false. Once again, adding apostrophes/quotation marks around a boolean turns it into a string. Asking JavaScript if 25>4 is 'true' will do nothing, since 'true' or 'false' is a string and not a boolean. However, asking JavaScript if 25>4 == true will get you somewhere, because JavaScript knows to check if the value or variable is true. One thing about booleans is that you actually don't need the words true or false sometimes. The code: if (variable == true) { } is the same as: if (variable) { } Hope that helps!
8th Aug 2016, 7:57 PM
Hailey
+ 1
Thanks For guidance 😊
9th Aug 2016, 6:26 PM
hamza hafeez
hamza hafeez - avatar
+ 1
wow alot of usefull info on js
11th Aug 2016, 9:07 AM
Jason Bohannon
Jason Bohannon - avatar