add <script>
tag just before the </body>
tag.
<body>
...
<script src="./some.js"></script>
</body>
- var (value can be updated)
- let (value can be updated)
- const (value can't be updated)
var name = "Wes";
let age = 100;
const cool = true;
-
represent letter, paragraphs, phases, etc. Can be declared with quotes, double-quotes or back ticks.
const name = "Wes"; const middle = "topher"; const last = `Bos`;
sentence
with "\ esc", quotes, single quotes and backtick option:
sentence = She´s so "cool"const sentence = 'she´s so "cool"'; const sentence = 'she´s so "cool"'; const sentence = `She's so "cool"`;
concatenation & interpolation
const hello = `hello my name is ${variable_name} nice yo meet you. I'm ${ 30 + 5 } years old`;
-
Numbers on Javascript includes float, integers, etc ...
there are all the basic operation (addition, subtraction, multiplication and division).let a = 10 + 10; // addition let b = 20 - 10; // subtraction let c = 10 * 10; // multiplication let d = 100 / 10; // division let e = 1000 % 3; // modulo
Javascript have helper methods like:
Math.round(20.5); //result 21, round number up or down Math.floor(20.2); //result 20, will give you the lower Math.ceil(20.9); // result 21, will give you the upper Math.random(); // gives random number between 0 and 1
NaN is an other number, that means Not a number
let a = 10 / "dog"; console.log(a); // result: NaN
-
Everything in javascript is an object, are use for collections of data or functionality.
const person { firstName = 'Cesar', lastName = 'Gomez', age = '35' };
order doesn't matter in objects, we can access to the properties, the easiest way is:
person.firstName; // access to the first name properties person.lastName; // access to the last name properties person.age; // access to the age properties
-
Undefined: comes when you try to access toa variable that has been created, but not set.
let dog; console.log(dog); //result should be undefined
Null: is a value of nothing
let somethingNull = null;
-
Booleans: is a value of true or false, can be manually set or calculate:
//manually set let isDrawing = true; //calculate const age = 18; const ofAge = age > 19; console.log(ofAge); // result should be false
Equality: we have:
- = (setting or updating a variable)
- == (it compares the value but not the type of )
- === (compares the value and type of )
// = let dog = "Sharon"; // == "10" == 10; //result is true, it compares the value but not the type of (both values are 10) // === "10" === 10; // result is false, compares value and type of (first one is string, second one is number)
back to Table of Content
next Functions