
Follow to be enlightened!
#100DaysofCode
#Javascript
#CodeNewbies

β’ null
β’ undefined
β’ boolean
β’ number
β’ string
β’ object
β’ symbolβadded in ES6!
They are also called primitive types
#100DaysOfCode
#CodeNewbies

#100DaysOfCode
#CodeNewbie

#const - block scoped and fixed
#let - block scoped and reassignable
#var - global
#100DaysOfCode
#CodeNewbie

let holder = "data" //assigns string value to variable
const PI = 3.14 // assigns number value to variable
You can access variables depending on type of declaration used
#100DaysOfCode
#CodeNewbies

var phone_no = 0577464778 ;
var title = "Moon shining";
typeof phone_no //number
typeof title //string
#100DaysOfCode
#CodeNewbie

new String(lmao)
Object literal style: {}
Object properties describes things about your object
#100DaysOfCode

var My_array = [car, mat, dog]
#100DaysOfCode
#CodeNewbie

Function addNums (n1, n2) {
return n1 * n2 ;
}
addNums (1, 2); // 3
#100DaysOfCode
#CodeNewbie

var a = 3 * 6;
var b = a;
b;
3 * 6 is an expression (evaluates to the value 18), so is a and b. b = a is an assignment expression. var is a declaration statement
#100DaysOfCode
#CodeNewbies

var car = {name: audi,
color: blue,
price: 500,
models: { sport: 2007,
convertible: 2013},
}
access the color & sport property of car:
car.color // blue
http://car.model.sport // 2017
#100DaysOfCode

A[index] - A is the name of the array, index is the numerical position of the element starting from 0.
var Evens = [2,4,6,8,10]
Evens[0]; // 2
Evens[2]; //6
#100DaysOfCode
#CodeNewbie
#JavaScriptmas

var book =
{ name: demented,
color: red,
price: 199 }
var {name, color} = book;
name; //demented
color; // red
#100DaysOfCode
#CodeNewbies
#JavaScriptmas

#100DaysOfCode

function add (a, b, cB) {
return cB(a+b) ;
}
add(1, 2, function (c) {
console.log(c);
}) // 3
They're functions inside another function
#100DaysOfCode
#CodeNewbie
#JavaScript
concat()
copyWithin()
entries()
every()
fill()
filter()
find()
findIndex()
forEach()
from()
includes()
indexOf()
isArray()
join()
keys()
lastIndexOf()
map()
pop()
push()
reduce()
reduceRight()
reverse()
shift()
slice()
some()
sort()
splice()
toString()
unshift()
#100DaysOfCode
copyWithin()
entries()
every()
fill()
filter()
find()
findIndex()
forEach()
from()
includes()
indexOf()
isArray()
join()
keys()
lastIndexOf()
map()
pop()
push()
reduce()
reduceRight()
reverse()
shift()
slice()
some()
sort()
splice()
toString()
unshift()
#100DaysOfCode

splice(): Adds/Removes elements from an array
toString():Converts an array to a string
unshift(): Adds new elements to the beginning of an array, returns the new length
Mutation can be problematic
#100DaysOfCode

const verbs = [run, slap, eat]
const moreVerbs = [kill, sit, .
..verbs]
With it, you can clone an array or object and mutate it.
#100DaysOfCode
#CodeNewbie

const myAlphanums = { c: 3, d: 4 }
const moreAlphanums = { a: 1, b: 2, ... myAlphanums }
// {a: 1, b: 2, c: 3, d: 4,}
N/B: spread operators preserves order in the new array/object.
#100DaysOfCode
#CodeNewbie

You can iterate over the elements of an array, performing a consistent action to each item, with a for loop
for (const i = 0, i = evens.length, i++) {
return evens[i] * 2 ;
}
the i = 0 expression is evaluated before the code runs.
#100DaysOfCode

let a = 1
while (a < 5) {
console.log(a);
a++;
}
//1,2,3,4
Don't forget to increment the variable on every iteration so it doesn't run forever.
#100DaysOfCode
#CodeNewbie

var i = 0;
do {
console.log(i)
i++;
}
while (i < 5);
#100DaysOfCode

var profile = {fname:"John", lname:"Doe", age:45};
var text = "";
var v;
for (v in profile) {
text += profile[v];
}
N/B: You'll have reference the object's values in the block.
#100DaysOfCode
#CodeNew

var car = {name: "BMW", color: "red", model: 2005};
var x;
for (v of car) {
document.write(v + "<br >");
}
//BMW
red
2005
#100DaysOfCode
#CodeNewbie

let car = new Map()
.set('name', 'Audi')
.set('size', 'large')
.set('color', 'red');
car.get('color'); // 'red'
car.delete('color') //deleted
#100DaysOfCode

let names = new Set();
names.add('joe');
// Set { 'joe'}
names.add('poe');
// Set { 'joe', 'poe'}
names.add('poe');
// Set { 'joe', 'poe'}
#100DaysOfCode

β’ String
β’ Number
β’ Boolean
β’ Object
β’ Function
β’ Array
β’ Date
β’ RegExp
β’ Error
See the next tweet

#100DaysOfCode
#CodeNewbie
Each of the built-in functions can be used as a constructor, the result being a newly constructed object of d subtype in question.
var strPrimitive = "I am a string";
typeof strPrimitive; // "string"
var strObject = new String( "I am a string" );
typeof strObject; // "object"
var strPrimitive = "I am a string";
typeof strPrimitive; // "string"
var strObject = new String( "I am a string" );
typeof strObject; // "object"

var a = 42;
var b = String( a );
var c = "3.14";
var d = Number( c );
b; // "42"
d; // 3.14
variable a is coerced into a string and c is coerced into a number.
#100DaysOfCode
#CodeNewbie

They are similar to the for() index loop.
#100DaysOfCode

const teams = [
{ name: "Man U",
points: 40 },
{name: "Arsenal"
points: 32}
]
var newT= teams .map(team => { team.points + 3 })
// [
{ name: "Man U",
points: 43 },
{name: "Arsenal"
points: 35}
#100DaysOfCode

const teams = [
{ name: "Man U",
points: 40 },
{name: "Arsenal"
points: 38},
{name: "Spurs"
points: 35}
]
var NewT = teams .filter(team=> team.points > 36);
// [
{ name: "Man U",
points: 40 },
{name: "Arsenal"
points: 38}
]
#100DaysOfCode

const ppl = [
{
name: 'Jim',
status: ['Married'],
},
{
name: 'Anna',
status: ['Married', 'Parent'],
},
{
name: 'Ed',
status: ['Married''],
},
];
const prnt = ppl.find(person =>person.status.includes('Parent''));

const names = ['mark', 'jane'];
let capitalized = [];
names.forEach(name => capitalized.push(name.toUpperCase()));
capitalized;
// ['MARK', 'JANE'];
#100DaysOfCode