![]() Now that you've helped complete the show component, it's time to work on an individual episode component. Head to CodePen Exercise P1CH3a and follow the instructions below to practice using three primitive types: numbers, strings, and booleans. Other more sophisticated operators exist for strings, and we will explore them in later chapters. Strings can also be concatenated (one added to the end of another) using the + operator: let wholeName = firstName + ' ' + lastName // value: "Will Alexander" String variables are enclosed in single or double quotes - ' or ": let firstName = "Will" Anything from one letter to quite a large number of letters (over 134 million even in older browsers) can be stored in a variable of type string: Strings of characters (or just strings) are how you store text in JavaScript variables. īoolean variables hold one of two values: true or false. They are used in all sorts of cases: whether or not a user is signed in, a checkbox is checked, or a specific set of conditions are met. Booleansīooleans are the simplest of the primitive types: they hold the values true or false. Where possible, use integer calculations instead (when calculating prices, for example, think in cents, not euros or dollars). Beware of floating-point arithmetic! įloating-point arithmetic can throw up really weird errors in all programming languages: let integerCalculation = 1 + 2 // gives 3 In programming, whole numbers are known as integers, while numbers with figures after the decimal point are known as floating-point numbers. They can also be whole numbers (1, 2, 3, etc) or decimals (1.4, 67.34, etc). Variables of type number can be either positive or negative. ![]() ![]() As you have seen, they can be manipulated mathematically in many different ways. ![]() NumbersĪll of the variables you have created so far in this course have been of type number. While you do not need to declare a variable's type in JavaScript (more on this a little later), it is important to understand their existence and importance. Primitive types are the basic building blocks of every data structure in JavaScript. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |