00:12 Different programming languages deal with the declaration, management, and manipulation of data differently. The design of a language determines what it means to be an integer and what happens when integers interact with floats or strings.
00:35 Dynamic typing means the type of the data is decided at runtime, whereas static typing means it is determined at compile time. Dynamic typing is a bit more flexible, whereas static typing allows the compiler to catch problems that you would not discover until running a dynamically-typed program.
01:03 It was introduced by TypeScript and was added in Python 3. Type hinting is a mechanism for annotating a piece of data with a type but then using a separate tool to determine compliance. Your IDE or a code checker like mypy can find the same kinds of problems that static typing would if you’ve been disciplined enough to annotate. This compromise allows you to get the benefits of static typing without mandating it and tying your hands when you want the more dynamic features of your language.
04:29 Notice that inside of Node.js, it automatically shows you the result of the declaration. This is different from the Python REPL on the left, where I had to explicitly show you the contents of data. Here’s a string.
You can’t add a string and a number, and Python tells you so with an exception. If you’re trying to get the
3 out of the string, you need to convert it to an actual integer, then you can do the addition.
2 into a string because the line begins with a string. If you’re not expecting this, this can be a bit disconcerting. It can also be a tricky source of bugs.
The plus sign (
+) means both addition and string concatenation. By contrast, the minus sign (
'3' into an integer and does the math for you.
symbol. This is an odd little meta-object. Each one of these you create is guaranteed unique. You can associate a name with them, but two symbols with the same name are still considered different.
undefined, which is also kind of like
None in Python. Yes, there are two ways of saying “empty.” I’ll talk more about this in a later lesson as well.
Reference types are closer in nature to objects in Python. Reference types do have methods and attributes. The built-in reference types are:
string primitive into a
String reference type and accessed the attribute all automatically. When I asked for the
new keyword here creates a new instance of the object. This is done by calling the object’s constructor. A constructor constructs a new instance of the object. Primitive types are stored on the calling stack.
09:26 Reference types are stored in the memory heap. This means that autoboxing is actually causing the underlying data to be moved in memory. Where the real difference between primitive and reference types is shown is how they are passed around. Let me create a primitive.
y is a copy, changing
x doesn’t change
y. Like Python strings, each of these are an immutable object. Technically, I didn’t change the value of
This can be expensive in memory and speed if you’re not careful. So, that’s primitive types. Now let’s look at how reference types are different. Here, I will create an object with an attribute called
This isn’t exactly the same, and I’ll go into more details in a future lesson on classes, but it’s a close enough analogy for now. The
.isPrototype() method on the
.prototype property will tell you whether the object in question inherits from a given parent.
Become a Member to join the conversation.