-
Notifications
You must be signed in to change notification settings - Fork 0
JavaScript
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.
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.
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);
* 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 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
Test the relative order of their two operands (
evaluates to true if its first operand is less than its second operand; otherwise it evaluates to false
evaluates to true if its first operand is greater than its second operand; otherwise it evaluates to false
evaluates to true if its first operand is less than or equal to its second operand; otherwise it evaluates to false
evaluates to true if its first operand is greater than or equal to its second operand; otherwise it evaluates to false
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
it returns false if two values are strictly equal to each other
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
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
a unary (consisting a single component) 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👇
var ageJohn = 28, ageMark = 33;
var johnOlder = ageJohn < ageMark;
console.log(typeof johnOlder);
console.log(typeof ageJohn);
console.log(typeof 'Mark is older than John');
the result for typeof 'Mark is older than John' is string
the result for typeof ageJohn is Number
the result for typeof johnOlder is Boolean
-
which means, which operator is executed first
var now = 2018; var yearJohn = 1989; var fullAge = 18;
in this line the - gets executed first, then >= and then = is last.
var isFullAge = now - yearJohn >= fullAge; //true
They are control statements which will execute or skip statements depending on the value of a specified expression. These statements are the decision points of your code.
if acts as the fundamental control statement which allows JavaScript to execute statements conditionally. There are two forms:
if (expression)
statement