Javascript Rest Operators and the “arguments” Variable

javascript rest operator and the argument variable
read about javascript rest operator and the argument variable

This article is all about javascript rest operators and how it could be used in javascript programming. A little discussion is also included for the arguments variable and how to process it inside a function.

Have you ever thought of how some Javascript built-in functions like Math.max() contain multiple arguments? Yes, it is possible – javascript functions may have an arbitrary number of arguments.

This is made possible with the javascript rest operators and it looks like this:

function getSum(...addends) {
  let sum = 0;
  for (let addend of addends) sum += addend;
  return sum;

alert( sumAll(1) ); // 1
alert( sumAll(1, 2) ); // 3
alert( sumAll(1, 2, 3) ); // 6

As you see in the function’s argument, we added three dots before our argument: addends. The three dots (…) also called the rest operator tells the function to merge the arguments in the function into an array.

In the function, we can then process the inputs similar to how we process arrays.

We must follow some rules though when we use rest operators. For example, it is not possible to place the rest operator at the first or middle part if your function has multiple arguments.

function person(...arguments, firstname, lastname) {
//the argument arrangement above does not make sense...

The above function does not make sense. So we must arrange the arguments like this:

function person(firstname, surname, ...args){
//this is clearer and this will work

Simply put: we must place the rest operator as the last argument.

The arguments variable

Another useful javascript trick is not placing arguments in the function. We may then process all inputs though with the argument variable. The argument variable is an array and we can process it like how we treat arrays. For example:

function testing(){
  for(var args of arguments){
    //arguments is the variable fed to testing function
    console.log(arg); //lets just output each argument


However, creating functions like this would result in readability problems. The reason is that we don’t know what inputs we’re feeding our function. The arguments variable though is NOT really an array such that may not work.

Another problem is: arguments can not be used with arrow functions. This will NOT work:

const arrowfunc = () => {
  for(var arg of arguments){

Take note that arrow functions cannot have their own this. They can not have their own arguments variable also.

Please follow and like us:

Laravel Notes

Laravel is a PHP development framework that adheres to the MVC (Model, View and Controller) paradigm. The framework was intended to be a better alternative to Codeigniter which is a different framework. It surpassed Codeigniter though in a lot of areas. These areas include but not limited to: built-in support for authentication, localisation, models, views, sessions, routing and other mechanisms.

Furthermore, Codeigniter development has ceased to evolved. New features are non existence making this framework obsolete. As a result, Laravel is now the goto framework for PHP developers.

Here are my notes to guide me when developing web applications using Laravel. Take note however, that you need to have PHP and Composer installed.

Creating a project

> composer create-project laravel/laravel project-folder #create project.

Invoking this command will create a project with project-folder as the folder of the project. This may take a while so you need to be patient on this. Once this is done, we may now start development of our PHP web application.


Basic Routing

Routing is essential to applications. We may set our routes on routes/web.php:

Route::get('/', function(){
 return "Hello World.";

Route::get('/about', function(){
 return view('pages.about');

To render our view, we may have the following code on resources/views/pages/about.blade.php

This is the about page.

We may call routes pointing to some information. These are called dynamic routes. For example, to view a certain person’s information, you may add the following code to your route.

Route::get('/person/{id}', function($id){
 return "this is person: " . $id;

The $id parameter here is a key to identify the person. We may use this variable to access information saved to the database.

Creating Controllers

> php artisan make:controller PagesController

PascalCase on the controller name. This will create a file under: app/Http/Controllers/PagesController.php

php artisan make:controller PostsController --resource

The above command will add a controller and CRUD placeholder functions (Create, Retrieve, Update and Delete) to it.

Creating a Model

> php artisan make:model Posts -m #when you want a migration script included
php artisan tinker




Please follow and like us:
Linux Logo

10 Linux Commands Developers should Know

Linux commands should be known by every developer. Even though, development may happen in one’s Windows or IOS, but when placed in the server, the server’s OS is most probably a Linux. This means that developers will have to navigate through it using Linux. So here is a list of 10 Linux commands that one should master.

Directory Management and Traversing

  1. ls
    Lists the content of the current directory. If a string (directory) is passed to it, it will list the content of that directory. Important switches (the ones that are preceded by -) are – lists all including filenames preceded with . (dot); – lists in long format – showing other information.
    >> ls #shows files on the current directory
    >> ls /var/www #shows files from directory: /var/www
    >> ls -a #shows all files including hidden files or files preceded by . (dot)
    >> ls -al #shows all files and their information
  2. cd
    Traverse to a different directory. If a .. is passed cd .. # double dot , will traverse to the parent directory. Passing a string as an argument will let it move towards that directory.  When the first character of the directory is / (slash), it will be relative to the root directory.
  3. pwd
    This will print the full pathname of the current working directory.
  4. mkdir
    This will create a directory. A very important switch is the – this will create parent directories if they don’t currently exist.
  5. Linux Commands for File Management

  6. rm
    This Linux command will remove files. An important switch for rm is -R (could also be -r or –recursive). This will recursively remove all files and directories. Another switch is f which will delete files without prompting you even when the file(s) are write-protected.
  7. cp
    Copy files or directories. This takes the format: cp [options] source destination. The most important option (switch) is: r (-R or –recursively) – which will copy files and directories.
  8. mv
    This will move a file or copy a file to a different filename. The format is mv [options/switches] source destination where the usual switches are f, i or r.
  9. Linux Commands for File/Directory Ownership and Permissions

  10. chmod
    This will change permissions on files or directories. The format is: chmod [options/switches] permissions filename_or_directoryExamples:
    >> chmod u=rwx,g=rx,o=r myfile #user can read,write and execute; group can read and execute; others can only read
    >> chmod 754 myfile #the same command above but in octal option
    >> chmod -R 755 myfiles #recursively go through all files in myfiles folder and change permission to 755
  11. chown
    This command will change ownership to a file or directory. The format is: chown [options] [user[:group]] filenam_or_directory. Only root can change ownership of a file. Even the owner cannot transfer ownership, unless the owner is root, or he is a sudoer and he prepends sudo to run the command. Examples:
    >> sudo chown user:ongroup myfile.txt #change ownership of myfile.txt to user and of group ongroup
    >> sudo chown -R myuser:mygroup otherfiles #recursively go through all files in otherfiles directory
  12. cat
    The linux command cat has three related functions with regard to text files: displaying them, combining copies of them and creating new ones. Examples:
    >> cat thefile #will output the content of thefile
    >> cat file1 > file2 #will copy the content of file1 to file2
    >> cat file1 file2 > file3 #will concatenate the content of file1 and file2 to file3

    These are only the essentials and I’m still planning to expand this with more complicated ones. Here are other Linux commands you can also master: ln – to create symbolic links between files; find – locate files; df – show disk usage; diff – compare two files; and grep – to look for text based on a regular expression patterns on files.

Please follow and like us:

TMUX Essentials

I got introduced to tmux when I joined a seminar on Docker. While listening to the speaker going through the topics, and seeing how easily he went through folders in Linux and how he switched between panes – I immediately saw a solution to some problems I have. When I reached home, I got my hands dirty…

From the tmux github repo:

Tmux is a terminal multiplexer. It lets you switch easily between several programs in one terminal, detach them (they keep running in the background) and reattach them to a different terminal. And do a lot more.

I keep several apps and services in the cloud. I connect to them via SSH using bash. Working on a terminal and running only one command each line is a headache for me. Much more, when the terminal times out you have to relogin again. Tmux is the solution to remedy these problems.

Currently, the only features from tmux that I’m using is opening several panes. Opening only two horizontal panes will do for me. I can move from one pane to the other. I can edit some codes on one, then move to the other pane to execute commands.

Several commands are available but here are the few that gets me through:

Starting/Ending a tmux server and/or session

>> tmux

Writing this on the Linux terminal will start the tmux server and an unnamed session. This gets me through when I’m on a hurry. But if you want to name it so you can get back to it  later, then you may

>> tmux new -s session_name

If you want to list the current sessions, you may write:

>> tmux list-sessions

The tmux server may be ended with the command:

>> tmux kill-server

Or to kill a session with name session_name you may:

>> tmux kill-session session_name

Tmux Panes and Pane Navigation

Some tmux commands are preceded by Ctrl+B. For example to create a horizontal pane you may write: Ctrl+B ” – which actually could be Ctrl+B Shift ‘.

Pane Commands:
Split current pane into 2 vertical panes: Ctrl+B %

Split current pane into 2 horizontal panes: Ctrl+B "

Show pane numbers: Ctrl+B Q

Shown pane number and go to that pane with pane_number (number designation): Ctrl+B Q pane_number

When traversing two panes, you may go from one pane to another with: Ctrl+B ;

Closing the current pane: Ctrl+B x (You may be prompted to answer y or n)


So there you go. These are the essentials I found so far.

Please follow and like us: