Variables and data types Flashcards
JS in loosely typed. What does that mean?
It means that a variable can be defined with just a name. Things like lenght and type are not declared
Are variables case sensitive
Yes
What must variables begin with
a character
What value will an variable with an unassigned value return?
Undefined
How many primitive data types are in JS?
Undefined
Number
String
Boolean
Object
Structural type
Give an example of an undefined data type
Var car;
Give an example of a number data type
var myweight = 20;
Give an example of a string data type
var dogname = “Isa”;
Give an example of a boolean data type
var theswitch = false;
Give an example of a number array data type
varnumarray = [1,3,5,7,9];
Give an example of an object data type
var myobj = {firstname:”Bob”,lastname:”Heide”};
Why are JS types considered dynamic?
Because the type changes based on the value of the var. For example var myname = “bob”; is a strin but I can then say myname = 3; and that changes the type to numeric
How can i display the type of a variable?
console.log(typeof myname);
What is the data type of the following statement
var fruit = “apple” + 3;
The type is string because it is set by the first part of the value which is a string
What would the value of the variable be? What would it’s type be?
var mynum = 5 + 3 + “gift”;
The answer is 8gift.
JavaScript moves left to right. In this case the numbers are treated as math and then the string is added. This makes the type string