/**********************************************
* JavaScript primitive types
**********************************************/
/**
* Strings
*/
writeTo('h1', 'Strings');
writeLn('This thing inside of this writeLn thing is a string');
writeLn("A string can be used with double or single quotes");
writeLn("It is really a matter of what you're intentions are for the type of quote");
writeLn('As someone once said - "Internet quotes are always true"');
writeLn("We can read our strings\
a little better if we put\
a backslash at the end of\
each line.");
console.log('html handles new lines a little differently, but the console uses\nescape sequences like "backslash n"');
writeLn('Strings can have escape sequences - that is a backslash followed by an identifier');
writeLn('We can do all sorts of fun things with this, like unicode');
writeLn('You may call me \u305B\u3093\u305B\u3044');
writeLn('We can concatenate,' + ' or join together,' + ' multiple strings with the "+" operator.');
writeLn('Strings have a type of - ', typeof('what am i?'));
/**
* Numbers
*/
writeTo('h1', 'Numbers');
writeLn('An integer is a ', typeof(3));
writeLn('A floating point number is a ', typeof(3.5));
writeLn('A hex value is also a ', typeof(0xAD));
//Floating point numbers can be represented in several ways
writeLn(3.295, ', ', .33333333333, ', ', 3.54e23, ', ', 1.785432E-26);
writeTo('h2', 'Arithmetic in JavaScript');
writeLn('2 + 2 = ', 2 + 2);
writeLn('5.9 - 2.5 = ', 5.9 - 2.5);
writeLn('3 * 3 = ', 3 * 3);
writeLn('14 / 7 = ', 14 / 7);
/**
* Boolean values
*/
writeTo('h1', 'Boolean values');
//Booleans represent what is true or false, what is on or off, what is yes or no
writeLn(true, ' is of type ', typeof(true));
writeLn(false, ' is of type ', typeof(false));
//We can negate the value of a boolean using the '!' operator
writeLn(!true);
writeLn(!false);
//Boolean values are generally the result of logical expressions and comparisons such as ==, >, <,...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.