Skip to content

JavaScript

Marie-Louise edited this page Jan 27, 2019 · 42 revisions

History

It was developed in 10 days by Brendan Eich for netscape navigator, one of the first internet browsers

JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996. It was originally going to be called LiveScript, but it was renamed in an ill-fated marketing decision that attempted to capitalize on the popularity of Sun Microsystem's Java language — despite the two having very little in common. This has been a source of confusion ever since.

Overview

JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well. JavaScript supports object-oriented programming with object prototypes, instead of classes. JavaScript also supports functional programming — functions are objects, giving functions the capacity to hold executable code and be passed around like any other object.

Variable Declaration

you can declare multiple variables at the top with same the var keyword var year, yearJohn, yearMark;

each variable needs to have a value assigned to it arithmetic operators

now = 2018;
ageJohn = 28;
ageMark = 33;

console.log(ageJohn);
console.log(now + 2);
console.log(now * 2);
console.log(now / 10);

Arithmetic Operators

* Multiplication

/ Division

% Modulo - It returns the remainder after whole number division of the first operand by the second operand

+ Addition - can also concatenate string operands

- Subtraction

++ Increment - adds 1 to..

-- Decrement - subtracts 1 to..

Relational Operators

Relational operators test for a relationship between two values then will return true or false depending on whether that relationship exists. They always evaluate to a boolean value. NOTE: string comparison is case sensitive and all capital ASCII are "less than" lowercase ASCII letters. For example Zoo < aardvark

Comparison operators

Test the relative order of their two operands (

Less than <

evaluates to true if its first operand is less than its second operand; otherwise it evaluates to false

Greater than >

evaluates to true if its first operand is greater than its second operand; otherwise it evaluates to false

Less than or equal <=

evaluates to true if its first operand is less than or equal to its second operand; otherwise it evaluates to false

Greater than or equal >=

evaluates to true if its first operand is greater than or equal to its second operand; otherwise it evaluates to false

Strict equality ===

checks whether its operands are "identical" using a strict definition of sameness that does not include any type conversion of the operands. If the operands have different types, they are not equal. If both operands are primitive types (Boolean type, Null type, Undefined type, Number Type, String type, Symbol type) and their values are equal, they are equal. If both operands refer to the same object object, array or function, they are equal....TBC

Strict inequality !==

it returns false if two values are strictly equal to each other

Loose equality ==

If the values of the two operands are not the same data type, it will attempt some type conversions and tries the comparison again. for example 1 == "1" evaluates to true

Type conversion / coercion

Javascript will convert the data type as it is needed so for example:

var firstName = 'John'; //string literal
var age = 28; //number

console.log(firstName + ' ' + age);

In the console, the var age is converted and the both will display as strings.

or

var job, isMarried;

job = 'teacher';
isMarried = false;

console.log(firstName + ' is a ' + age + 'year old' + job + '.Is he married?' + isMarried);

will also display as a string

The Typeof Operator

a unary operator that is placed before its single operand, which can be of any type. Its value is a string that specifies the exact type of the operand. So for example👇

console.log(typeof johnOlder);
console.log(typeof ageJohn);
console.log(typeof 'Mark is older than John');
var x;
console.log(typeof x);

Package.JSON

Objects

Functions

ECMAScript

Variable scope

Data Types

Clone this wiki locally