Currently browsing author

Page 3

JavaScript – Objects and Methods

One of the most important features in JavaScript. Objects and properties In objects, we define key-value pairs which means each value has a name which is called the key. Objects are like containers which can store variables called properties. One fundamental differences between an object and an array is that in array order matters a lot while in object it does not matter at all. Steps Declare a variable var john = The easiest way to create a object is the so called object literal. Continue reading →

JavaScript – Arrays and Useful Methods

Arrays are like collections for variables that even have different data types. There are multiple ways to create arrays, the simplest way it through var names = []; var names = ['John', 'Mark', 'Jane']; or calling the Array() with the new keyword var years = new Array(); var years = new Array(1990, 1969, 1948); Arrays are zero based, which means that the first element is element number 0. Continue reading →

JavaScript – Truthy, Falsy Values and Equality Operators.

A falsy value in JavaScript is considered false when it is evaluated in a if/ else statement condition. Falsy values in JS include: undefined null 0 (zero) empty string NaN All these values will be converted to false in a if/else condition, that’s why we call it falsy, they are not essentially false but are converted to false when evaluated in a true/ false condition. Truthy values: Those that are not falsy Example: var height; if(height){ console.log('Variable is defined. Continue reading →

JavaScript – Ternary Operator & Switch Statements

  Ternary operator it’s basically an operator that allows us to write if-else statement in one line. It’s called ternary because it has three operands. var name = 'John'; var age = 16; age >= 18 ? console.log(name + ' drinks beer.') : console.log(name + ' drinks juice.'); Steps: We have the condition first followed by ? then if block the else block   Assign value to variables using ternary operators. var age = 20; var drink = age > 18 ? 'beer' : 'juice'; console. Continue reading →

JavaScript Operators

    Math Operators: Β – Β + Β * Β  /   Logical Operators: > < result in boolean values   Typeof Operators: we only need one operand for typeof operator. console.log(typeof(year)); //number Operators Precedence var now = 2018; var yearJohn = 1989; var fullAge = 18; var isFullAge = now - yearJohn >= fullAge; console.log(isFullAge); //true How JS knows which operators to execute first? ==> This is due to operator precedence. Continue reading →

JavaScript (ES5) – Variable Mutation and Type Coercion

Let’s see how to comment in JavaScript first, there are two types of comments: Single line comment // Variable naming rules Multi-line comments /* lorem ipsm */ Variable Mutation var firstName = 'John'; var age = 28; console.log(firstName + ' ' + age); //John 28 So how does this work as age is a number while firstName is a string ? This works thanks to type coercion where JS automatically converts data type from one to another when that is needed. Continue reading →

JavaScript Variables (ES5)

  What is a variable? It’s like a container that we can used to store value which can be used over and over again instead of writing each time we want to use it. Steps to declare a variable var keyword followed by the name of the variable ( in this case is firstname) the value we want to assign to the variable var firstName = 'John'; We can think of this firstName variable as a piece of memory in our computer in which this John string is stored. Continue reading →