Posts

=== or == JavaScript comparison operator

Introduction
triple equal === strict and double equal == not type strict are two of JavaScript comparison operators blatantly they are almost the same with an exception.== operator
this type of comparison operator is suitable for basic comparison between two items it's not type strict and normally discouraged unless otherwise and here's why i say so.
Take for instance
console.log((1 == "1")) // returns true
regardless of the fact that "1" is a string and 1 is a Number
because "1" is type casted  to a Number before comparison between the two values is done
Take for instance
var one = 1;
// console.log(typeof one) // Number
It's not a matter of concern neither is it a bug it's because JavaScript is a dynamic typed programming language.=== orstrictoperator
triple equal sign operator or strict operator is an operator that takes account of types of values before evaluating their similarities unlike the double equal sign operator strict operator…

How to train a tfjs model to play breakout game

Description
This is an artificial intelligence mechine learning practical experiment documentary on training an artificial intelligence neural network to play breakout game in the browser powered by tensorflow tfjs for JavaScript.
Introduction
To understand how things will work breakout is a game which is alot more like ping pong your objective is to make sure the ball never goes by the puck in other words the player's puck should hit the ball before it heads into the lower bond of the screen.
Second objective
Second objective is to make the ball destroy blocks by projecting it into the disired direction.
Normally this is not very important because the ball would normally iterate each and every corner on its own without trouble
Persudo code
below is how this system works
// start initialization
// create model
// end initialization // start update loop
async predict(should i move left or right). On resolve {set linear velocity} if(ball crashed) {diagnose errors and generate reinforced …

removing array elements in JavaScript

JavaScript array elements can be removed in multiple ways using methods pop, shift, splice, filter.Array.shift()
Shift is a method which knocks off the first most element of an array and returns it! ie
var number = [0, 1, 2, 3, 4, 5]
number.shift() // returns 0
console.log(number) // [1, 2, 3, 4, 5]Array.pop()
this method removes the last element off an array and returns the removed element ie
var number = [0, 1, 2, 3, 4, 5]
number.pop() // returns 5
console.log(number) // [0, 1, 2, 3, 4]
Array.splice(start, elements)
start is the index at which removing  starts elements is an integer the number of elements to remove it returns spliced elements
var number = [0, 1, 2, 3, 4, 5]
number.splice(0, 1) // returns 0
start can also be a reference ie of an object.

rgb to hex conversion in JavaScript

A handy function to convert rgb colors to hex in JavaScript
parameters: red, blue, green values.
returns a hex string which is 7 characters long including the hashfunction toHex(r, b, g) {
return "#" + [r, b, g].map(param => {
var hex = Number(param).toString(16)
return (hex.length < 2) ? '0' + hex : hex
}).join('')
}For instance  toHex(0, 0, 0)
// returns #000000

JavaScript intro to classes

Classes are objects 'functions which introduce inheritance parent child relationship in JavaScript it promotes code reusability which reduces the amount of code in a JavaScript application. JavaScript class decelerations start with keyword class proceeded by class name with a class body having a constructor along with methods for instance
class human {
    constructor(name) {
         this.name = name;
         this.gender = null;
    }
    great() {
        return "Greetings " +
        (this.gender == "male") ? "mr " : "mrs " + this.name
    }
} Child classes are created by adding the keyword extends followed by the parent class name and parent class methods can be called using the syntax super.+"method name"(parameters) class man extends human {
    constructor(name) {
         super(name)
         this.gender = "male";
    }
} const John = new man("John swana")
John. greet()
// returns Greetings mr John Swan…

Npm how to install webpack nodejs

A guide on how to install webpack bundler and webpack-cli using npm package manager first thing install webpack it's recommended not to install webpack globally to avoid conflicts with webpack versions npm i webpack -D
Note it's installed as a developer dependency. You'll also need to install webpack-cli
npm i webpack-cli -D
Again as a developer dependency.

hello world application in nodejs

Nodejs is a JavaScript command line runtime using chromes v8 engine known for its wicked fast speed and execution time. its well known that  the v8 engine compiles JavaScript to archive its impressive performance. Nodejs is a command line application ie the output will be forwarded to the console in our case the terminal of your shell. In your terminal or text editor type
console.log("Hello World") save the file simply as helloworld.js
In your terminal type node helloworld.js
Output // Hello World
// Hooray You dit it.

Adding elements to an array in JavaScript

JavaScript arrays are objects which can be initialized using a syntax of
["", ...] Parentheses with a number of elements ie
var oddNumbers = [2, 4, 6]
or var numbers = ["one", "two", "three"]
Or the global Array constructor using syntax ie  var integer = new Array(length = 2) console.log(integer) // [null, null]
where length species blank filler value by default the element is null and you can't iterate them to change the fill value you can call the fill method of an array ie integer.fill(0) console.log(integer) // [0, 0]

You can append an element to any of the arrays declared above using push , prepend using unshift, assign using manual assigning
Manual assignment Simplest way is by simply assigning a new element
oddNumbers['index'] = "Number"
ie oddNumbers[3] = 8;
console.log(oddNumbers) // [2, 4, 6, 8]
Push Its a method for appending elements to an array is oddNumbers.push(0) console.log(oddNumbers) // [0, 2, 4, 6, 8]
Unshift Its a…

Npm nodejs yarn install

Assuming you have installed nodejs on your system next thing is installing developer build tools and yarn is a must yarn is a nodejs package manager similar but different to npm which is installed by default immediately you install nodejsOpen a terminal session onto it type
sudo npm install yarn -gYarn is going to have a symbolic link in the bin so don't omit sudo or you'll probably get an ugly error if you are not a super user ie root.lastly -g argument specifies the package should be installed globally

How to install nodejs on linux

Nodejs is an open source JavaScript runtime without a dom model nodejs can be used to create web servers api's  and command line applications among others its important to note nodejs is increasing popularity due to its simplicity , speed and developer friendliness i.e frontend developers once limited to using JavaScript in the browser can now create server side backend applications.in your terminal execute the command below to add node js repository.
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -update apt packages list
sudo apt apt update && upgradeinstall latest nodejs
sudo apt install nodejs