JavaScript Basis: Syntax & Structure

February 08, 2019 0 Comments

JavaScript Basis: Syntax & Structure






JavaScript: the Values





18 // A number 'Toy' // A string (can be in double "" or single '' quotes) false // A boolean (can be true or false) ['a', 'b'] // An array {color: 'red', shape: 'Circle'} // An object



For instance, the key is defined as a variable.

const key;
key = pluto;





Camel Case




What solution do we propose?

camel case! e.g. firstItem.







let a = 500;
a = b + c;
const time =; 


// valid!
let a = 500
a = b + c
const time =


for (i = 0; i < .length; i++) { } 


if (name == "Silvia") { // code } // <- no ';'
function people(name) { // code } // <- no ';'

If we’re using an object however, like:

const person = { firstName: "Silvia", lastName: "Brown", age: 30, eyeColor: "green" }; // the ';' is mandatory



if (loginSuccessful === 1) { // run code } else { // abort }


if (loginAttempts < 5){ if (loginAttempts < 3){ alert("< 3"); } else { alert("between 3 and 5"); } } else { if (loginAttempts > 10){ alert("> 10"); } else { alert("between 5 and 10"); } }


White Space


const visitedCities="Rome, "+"Florence, "+"Venice"; const visitedCities = "Rome, " + "Florence, " + "Venice";

Don't tou think the second one's more readable?

Another example:

let x=1*y; let x = 1 * y; 





// Comment goes here
/* Comment goes here */




JavaScript Identifiers are names given to variables, functions, etc.




// Valid :)
Name name NAME _name Name1 $name
// Invalid :(
1name [email protected] name! 


Case Sensitivity


The following will throw an error:

function test() { alert("This is a test!"); }
function show_alert() { Test(); // error! test(); is correct }

Reserved Words

What reserved words are there in JavaScript?



See the full list of reserved keywords.

JavaScript Operators



(2 + 2) * 100

The assignment operator = is used to assign values to our variables

JavaScript Expressions


  • Arithmetic expressions
  • String expressions
  • Primary expressions
  • Array and object initializers expressions
  • Logical expressions
  • Left-hand-side expressions
  • Property access expressions
  • Object creation expressions
  • Function definition expressions
  • Invocation expressions


Under this category go all expressions that evaluate to a number:

1 / 2 i++ i -= 2 i * 2 


Expressions that evaluate to a string:

'A ' + 'string' 'A ' += 'string' 


Under this category go variable references, literals and constants:

2 0.02 'something' true false this //the current object undefined i //where i is a variable or a constant 

but also some language keywords:

function class function* //the generator function yield //the generator pauser/resumer yield* //delegate to another generator or iterator async function* //async function expression await //async function pause/resume/wait for completion /pattern/i //regex () // grouping 


[] //array literal {} //object literal [1,2,3] {a: 1, b: 2} {a: {b: 1}} 



a && b a || b !a 


new //create an instance of a constructor super //calls the parent constructor ...obj //expression using the spread operator 

PROPERTY ACCESS EXPRESSIONS //reference a property (or method) of an object object[property] object['property'] 


new object() new a(1) new MyRectangle('name', 2, {a: 4}) 


function() {} function(a, b) { return a * b } (a, b) => a * b a => a * 2 () => { return 2 } 


The syntax for calling a function or method

a.x(2) window.resize() 




We hope you found this article useful!

Tag cloud