Vincent Lab

Vincent Lab

1605017502

The Difference Between Regular Functions and Arrow Functions in JavaScript

Other then the syntactical differences. The main difference is the way the this keyword behaves? In an arrow function, the this keyword remains the same throughout the life-cycle of the function and is always bound to the value of this in the closest non-arrow parent function. Arrow functions can never be constructor functions so they can never be invoked with the new keyword. And they can never have duplicate named parameters like a regular function not using strict mode.

Here are a few code examples to show you some of the differences
this.name = "Bob";

const person = {
name: “Jon”,

<span style="color: #008000">// Regular function</span>
func1: <span style="color: #0000ff">function</span> () {
    console.log(<span style="color: #0000ff">this</span>);
},

<span style="color: #008000">// Arrow function</span>
func2: () =&gt; {
    console.log(<span style="color: #0000ff">this</span>);
}

}

person.func1(); // Call the Regular function
// Output: {name:“Jon”, func1:[Function: func1], func2:[Function: func2]}

person.func2(); // Call the Arrow function
// Output: {name:“Bob”}

The new keyword with an arrow function
const person = (name) => console.log("Your name is " + name);
const bob = new person("Bob");
// Uncaught TypeError: person is not a constructor

If you want to see a visual presentation on the differences, then you can see the video below:

#arrow functions #javascript #regular functions #arrow functions vs normal functions #difference between functions and arrow functions

August  Larson

August Larson

1624357980

String Format() Function in Python

To control and handle complex string formatting more efficiently

What is formatting, why is it used?

In python, there are several ways to present output. String formatting using python is one such method where it allows the user to control and handle complex string formatting more efficiently than simply printing space-separated values.There are many types of string formatting, such as padding and alignment, using dictionaries, etc. The usage of formatting techniques is not only subjected to strings. It also formats dates, numbers, signed digits, etc.

Structure of format() method

Let us look at the basic structure of how to write in string format method.

Syntax: ‘String {} value’.format(value)

Let us look at an example:
‘Welcome to the {} world.’.format(“python”)

Here, we have defined a string( ‘’) with a placeholder( {} ) and assigned the argument of the parameter as “python.” On executing the program, the value will be assigned to the placeholder, showing the output as:

#python #programming #string format() function in python #string format() function #format() #format() function

Myriam  Rogahn

Myriam Rogahn

1599564660

Scala Beginner Series (1) : Basics

This series is all about the Scala and is best suitable for all the newbies in Scala.

This article will cover the fundamentals of the Scala language.

Values

In Scala, we work with values:

Values are used to define constants. val modifier means constant or immutable that means we cannot change its value once it is created. Thus reassignment to val is prohibited.

It is evaluated at time of definition only. Once evaluated, it reuses same value for all references of it.

Variables

Scala also allows us to define mutable values. Variables are used to define mutable reference to a value. var modifier means changeable or mutable that means we can change its value throughout the program lifetime . Thus reassignment to var is allowed.

We do have the notion of a variable in Scala, but it’s heavily discouraged. In general, we work with immutable data structures: any intended modification to an existing instance should return a new (modified) instance.

Types

In Scala, we don’t always need to specify the data type of our value, because the compiler is smart enough to infer that for us. We can also write:

We can see, the compiler automatically inferred the data type of the value.

Strings

Strings in Scala are similar to what we see in other languages, but with some special functionalities:

Strings are defined as:

Whenever compiler encounters a string literal in the code, it creates a String object of java.lang.String class with its value.

Methods used to obtain information about an object are known as accessor methods.

One accessor method that can be used with strings is the length() method, which returns the number of characters contained in the string object.

The String class includes a method concat() for concatenating two strings. But strings are more commonly concatenated with the + operator.

String interpolation can also be done using string interpolator. It allows the direct usage of variable in processing a string, by injecting a value with the $ sign.

Expressions

In Scala, we work with values and we compose them to obtain other values. The composition structures are expressions**, **and they’re exactly what we expect.

Previously we have defined values assigned to literals. However, it is more accurate to say that they are assigned to the return value of expressions.

Thus expression is a single unit of code that that can be reduced to a value. It can be a literal, a calculation, or a function call. An expression has its own scope, and may contain values local to the expression block.

#java #tutorial #scala #functions #types #strings #variables #expressions #scala basics

Quinten  Boehm

Quinten Boehm

1626965351

2021 Dart Programming Language Tutorial for Beginners #2 Data Type & Variable

Welcome to my Dart programming language tutorial#2. In this series you will
be introduced to variables and learn how to declare them in Dart. Also I will cover some tip and code style which prefer by official Dart team.

Source Code: https://github.com/Rea2er/dart-tutorial

#dart #dart programming #tutorial #dart programming language #data type & variable

August  Larson

August Larson

1624945440

Basic Variable Types in Python

This written lesson is part of Banana Chip Tech’s Python Crash Course. For video lectures, programming homework assignments, and other content please visit our website.

Variables are ways that we can store information for use later on in a program. For this reason, they are incredibly helpful when programming. The way that I like to think about variables are like jars where we can stuff information in and then take information out later. A good real world example of what a variable does can be found in food containers. The food container itself would be the variable and the food that it holds would be the data that a variable would hold. For instance, we can store some peanut butter in our peanut butter jar. We can then take our peanut butter out of the jar and use it when we want to make our peanut butter and jelly sandwich. Similarly, we can have a pizza box which is holding our pizza. Later on when we are hungry, we can take out a piece of pizza and eat it. Both the peanut butter jar and pizza box act as storage containers, but _what _they store is different. All python variables store information, but the type of information that they store differs.

While python doesn’t force you to document what specific type of variable you’re going to be using, knowing the type of variable used can be critical for the success of your program. I like to classify python variables into two distinct types: basic variable types and data structure variable types. In this tutorial, we talk about the different basic variable types.

Basic variable types contain only a single piece of information. These basic variable types are like our peanut butter jar that only stores peanut butter. We can’t store cheese or bread in our peanut butter jar; we can only store peanut butter!

The first basic variable type that we will discuss is the integer (int). Ints are whole numbers that don’t have a decimal. They can be positive or negative as long as they don’t have a decimal. The following code provides a demonstration of creating an int. Notice that the equal sign is used to assign the value 3 to the variable named myint. For simplicity sake, I recommend using only letters and underscores in your variable names. Avoid using any keywords (ie: for, in, while, if, etc) in your variable names. Following these recommendations will help you avoid any invalid variable names!

#variables-in-python #python3 #python #programming #variables #basic variable types in python