1 00:00:00,460 --> 00:00:03,260 There are two ways of creating variables in Scala. 2 00:00:03,260 --> 00:00:07,780 The preferred way is by creating a constant using the key word val. 3 00:00:07,780 --> 00:00:12,800 This way of creating a variable supports the second idea of functional programming, 4 00:00:12,800 --> 00:00:15,920 as the contents of a val cannot be changed. 5 00:00:15,920 --> 00:00:19,060 Additionally, you can create a mutable variable in Scala 6 00:00:19,060 --> 00:00:22,680 by using the key word var whose contents can be changed. 7 00:00:23,720 --> 00:00:27,930 Let's see how this works in the REPL, the interactive shell, which we can get to by 8 00:00:27,930 --> 00:00:32,740 opening up a terminal in a Mac or command prompt in Windows and typing Scala. 9 00:00:33,800 --> 00:00:37,200 Let's open up the terminal to start the Scala REPL. 10 00:00:37,200 --> 00:00:41,088 REPL stands for read, evaluate, print, and loop, and 11 00:00:41,088 --> 00:00:44,328 it's very useful in evaluating expressions. 12 00:00:53,309 --> 00:00:55,795 Here, we've created a variable name greeting. 13 00:00:55,795 --> 00:00:58,905 A constant whose values cannot be changed. 14 00:00:58,905 --> 00:01:02,365 Attempting to reassign the value of variable greeting 15 00:01:02,365 --> 00:01:05,015 will throw a reassignment to val error. 16 00:01:05,015 --> 00:01:06,143 Let's take a look at that. 17 00:01:10,674 --> 00:01:14,557 Let's take a similar approach, but with a mutable variable this time. 18 00:01:19,795 --> 00:01:24,785 We've created a variable called message, which contains the string, hello world. 19 00:01:24,785 --> 00:01:28,227 Because vars are mutable, we can reassign its value. 20 00:01:33,657 --> 00:01:37,130 In both instances, you may have noticed two things. 21 00:01:37,130 --> 00:01:41,790 First, we aren't required to provide a semicolon at the end of the statement, and 22 00:01:41,790 --> 00:01:45,530 that's because Scala supports semicolon inference. 23 00:01:45,530 --> 00:01:49,120 Second, we didn't have to specify the parameter type. 24 00:01:49,120 --> 00:01:53,020 That's because scala has a built in type inference mechanism 25 00:01:53,020 --> 00:01:57,070 which allows it to figure out what the type of variable should be. 26 00:01:57,070 --> 00:02:01,080 Although not recommended, we can always supply the semicolon or 27 00:02:01,080 --> 00:02:04,110 the type information if we really wanted to. 28 00:02:04,110 --> 00:02:05,473 Let's take a look. 29 00:02:12,543 --> 00:02:16,930 Awesome, we learn how to create values and variables in Scala. 30 00:02:16,930 --> 00:02:21,760 In the next video, we will create our first Scala app and learn about functions. 31 00:02:21,760 --> 00:02:22,260 See you there!