JavaScript Quiz: Variables and Data Types
Which keywords can be used for the declaration of variables or constants?
// variable declaration let a = 1; // constant declaration const C = 3; // legacy variable declaration (not recommended any longer) var b = 2;
How to determine the type of a variable?
typeof aVariable;
Three ways to define a string.
let doubleQuotes = "string with double quotes"; let singleQuotes = 'string with single quotes';
There is no difference in behavior between double and single quotes. Double quotes are more Java-like, whereas single quotes are handy when used directly inside HTML code.
let backtick = `You can use either "${doubleQuotes}" or '${singleQuotes}' `;
Backtick notation allows for embedded expressions, and implicit line breaks (without "\n\").
How to define numbers?
// integers and floats are both stored with the data type "number": let x = 42; let y = 42.3; // for big integers, use the "n" suffix: let z = 84n
What is the difference between "undefined" and "null"?
let x; // at this point, x is still undefined: console.log(x); // x becomes null when explicitly assigning it: x = null; console.log(x);
How to create an object using literal notation?
let x = { a: 1 };
How to create an array object using literal notation?
let x = [1, 2, 3];
How to create a regular expression object using literal notation?
let x = /ab+c/;