//Example Variables var x = 5; var y = 6; var z = x + y; // or 11 // Same result, but "let" let x = 5; let y = 6; let z = x + y; // Again, but "const" const x = 5; const y = 6; const z = x + y; //Mixed Concept const price1 = 5; const price2 = 6; let total = price1 + price2; // You can declare many variables in one statement. // Start the statement with let and separate the variables by comma: let person = "John Doe", carName = "Volvo", price = 200; // A declaration can span multiple lines: let person = "John Doe", carName = "Volvo", price = 200; // JavaScript Dollar Sign $ // Since JavaScript treats a dollar sign as a letter, identifiers containing // $ are valid variable names: let $ = "Hello World"; let $$$ = 2; let $myMoney = 5; //In JavaScript, the equal sign (=) is an "assignment" operator, not an "equal to" operator. //This is different from algebra. The following does not make sense in algebra: x = x + // JavaScript variables can hold numbers like 100 and text values like "John Doe". // In programming, text values are called text strings. // JavaScript can handle many types of data, but for now, just think of numbers and strings. // Strings are written inside double or single quotes. Numbers are written without quotes. // If you put a number in quotes, it will be treated as a text string. Example : const pi = 3.14; let person = "John Doe"; let answer = 'Yes I am!'; // As with algebra, you can do arithmetic with JavaScript variables, using operators like = and + : let x = 5 + 2 + 3; // You can also add strings, but strings will be concatenated: let x = "Venus" + " " + "Martinez"; // Also try this : let x = "5" + 2 + 3; // Hint #523
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter