React Native Geeks

React Native Geeks Welcome to all react native mobile apps developers!

Array methods are powerful tools in logic building. Must do deep learning of these methods. The best way to learn these ...
22/09/2023

Array methods are powerful tools in logic building. Must do deep learning of these methods. The best way to learn these methods with practice is to go on sources like w3school.com and do exercises of these methods.

JavaScript Array Methods
More ☞ https://morioh.com/p/3ba421a8a63d

21/09/2023
Results don't appear at first. Many of us loose patience even when they get closer to the target. Whenever, you get a fe...
19/09/2023

Results don't appear at first. Many of us loose patience even when they get closer to the target. Whenever, you get a feeling of giving up remember the image that I have copied from the book 'Atomic Habit'.
The writer has tried to explain that whenever a person tries learning new thing, he/she will definitely does not see the expected results immediately. Rather there is a valley of disappointed, once successfully surpasses this zone then results will appear exponentially, even with lesser efforts. So, guys keep going, don't loose hope while in the stage of the valley of disappointment. Results will be fruitful for you after the break-even point. And they will become automated for you.....

19/09/2023

If you're like me, you've probably scratched your head more than once over the all-too-common JavaScript error message:

TypeError: can't access property "value" of undefined

You're not alone, even seasoned developers occasionally trip up when they encounter this.

✨ Key Insight: Contrary to what the error message suggests, the issue is rarely with the variable you're trying to access. Rather, it’s the parent object that's undefined.

πŸ’‘ What to Watch For: The real message hidden in the error is: "Hey, the object you're trying to read "value" from? Yeah, that one's undefined."

πŸ“ Pro Tip: Always check the line and column numbers in the error message; they are your allies in tracing back to the root of the problem.

Effective debugging involves questioning your initial assumptions. Within that questioning, we often find that we've made a wrong assumption that led us to reason about the code in the wrong way.

So the next time this confusing error pops up, you'll know exactly what to look for. It's this level of understanding that sets you apart as a developer.

Remember, we all make mistakes, but it's how we learn from them that defines us as developers.

Hope this helps someone today! What other JavaScript errors have you found tricky to debug?

Excuses keep you in your comfort zone....
18/09/2023

Excuses keep you in your comfort zone....

13/09/2023

TOPIC:
IMPORTANCE OF OBJECTS IN JAVASCRIPT AND CONCEPT OF MUTABILITY OF OBJECTS

Why understanding objects in JavaScript is so much important?
Objects are king in JavaScript.
Objects are variables too. But objects can contain many values.
for instance:
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
this object contains more values than a variable.
here firstName, lastName, age and eysColor are called properties and the value they hold are called value. the value of age is 50 here.

Can you guess what's the code below is about?

const person = {};
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";

here we created an empty object then added four properties in it.

we can achieve the same result with:
const person = new Object();
person.firstName= "John";
person.secondName = "Doe";
perosn.age = 50;
person.eyeColor = "blue";

OBJECTS IN JAVASCRIPT ARE MUTABLE. FOR INSTACNE WE MAKE A COPY OF AN OBJECT AND DO CHANGES TO IT. THIS WILL ALSO CHANGE THE ORIGINAL OBJECT, TOO.

For example:
const person = {
firstName:"John",
lastName:"Doe",
age:50, eyeColor:"blue"};

const x = person;

here x is the copy of the person

now if we make changes in x by

x.age=100;

these changes will also change the person(that was our original object).

13/09/2023

let's see .slice(), .split() and .splice() methods. .slice() is used to make a substring from a string. for example:
const paragraph =
"The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?";
and from this string if we want to cut out the portion starting from index 10 up to 50. we will do
console.log(paragraph.slice(10, 50));
it will give output as :
"brown fox jumps over the lazy dog. If th"

The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.

let's see the code in action:

const str = 'the quick brown fox jumps';
console.log(str.split(""));

here we will get output as:

['t', 'h', 'e', ' ', 'q', 'u', 'i', 'c', 'k', ' ', 'b', 'r', 'o', 'w', 'n', ' ', 'f', 'o', 'x', ' ', 'j', 'u', 'm', 'p', 's']
it means each character is now an element of the created array.
now if we do:
console.log(str.split(" "));
note that we have intentionally put a space between the inverted commas. this time the console will return:
['the', 'quick', 'brown', 'fox', 'jumps']
have you noticed the difference?
splice() method is used for changing the element at some specified index in an array. let's clear it with example. Suppose we have an array:

const fruits = ['apple', 'orange', 'banana', 'kiwi'];

now we want to replace the "orange" with mango. the index of orange is 1.
const summerFruits = fruits.splice(1, 1, "mango");
Here the first argument 1 means the index at which we want our replacement to be incorporated and the second 1 means the number of items that will be popped out of the array. and finally the 'mango' is the word that we want to be put at index 1 in this array.

console.log(summerFruits);

console will return ['orange'] as it has been omitted from the array.
now we want to check the changes in array :
console.log(fruits);
it will return :
['apple', 'mango', 'banana', 'kiwi']
orange has been replace with mango now.
Explore more in these method to mastery your skills.

13/09/2023

Other important methods for Arrays in JavaScript are:indexOf()
this method is used to check the index number of some specific word or character in a string:
const paragraph =
"The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?";
now we want to check the index of "lazy":
console.log(paragraph.indexOf("lazy"));
the console will return:
"35"
you can count from 0 onwards by yourself.....
lastIndexOf()
The lastIndexOf() method of String values searches this string and returns the index of the last occurrence of the specified substring. It takes an optional starting position and returns the last occurrence of the specified substring at an index less than or equal to the specified number.
let's see it by example again:
const paragraph =
"The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?";
console.log(paragraph.lastIndexOf("dog"));
console will return: 52

13/09/2023

Some of the most important methods for arrays in JavaScript:
1. .concat. The concat() function concatenates the string arguments to the calling string and returns a new string. Changes to the original string or the returned string don't affect the other.
example:
if we have a constant
const hello = "hello";

with another string we will do:

console.log(hello.concat(" how are you mr X");

the out put will be:
hello how are you mr X

2. .endsWith
this method is used to check whether a string ends with the specific character/word or not. let me clear it with one example:
we have a string

const str1 = "my name is david and i am react native geek";

console.log(str1.endsWith('ek'));

the console will return true because the str1 end with ek.

but it we check that:

console.log(str1.endsWith('st'));
the console will return false this time.

3. .charAt()
this function is used to check that in our string which character is residing at the specific index number. for example:

const test = 'The quick brown fox jumps over the lazy dog.';
const index = 4;
console.log(`The character at index ${index} is ${sentence.charAt(index)}`);
// Expected output: "The character at index 4 is q"

here through this method we have checked that which character resides at index 4 and that is "q".
Note: instead of defining another variable 'index' we can directly use the index number '4'. for instance:
cosole.log(sentence.charAt(4));
The output will be same again

4. .includes
now if we want to check that a string contains a specific character or not we will use function ".includes":
const sentence = "javascript is easy for those who practice it.";
i want to check that either "easy" is part of the sentence or not.
console.log(snetence.includes("easy"));
the answer will be "true".

Like and Share the post to know more to hep others in learning JavaScript Arrays and methods.
Stay Blessed...

11/09/2023

if you know the output of the following code then you know the concept of block and scope. let's check your skill
var firstName = "john";
function getName() {
var firstName = "peter";
console.log("inside the function", firstName);
}
getName();
console.log("outside the function", firstName);

first comment out the output of the above code. now if we change the code from function to 'if' statement the output will be differ. you can comment to get detailed understanding of the following code:
var firstName = "john";
if (true) {
var firstName = "peter";
console.log("inside the function", firstName);
}

console.log("outside the function", firstName);

the output in this case will be :
inside the function peter
outside the function peter

this is because in ES5 no block other than function can create a scope.
in previous case the function was used to get the output and the terminal was showing
inside the function peter
outside the function john
This is because the functions have ability to make the block scope in ES5.
If we have used the "let" keyword the out put would have been different.
let's see how "let" keyword will give different output:
let firstName = "john";
if (true) {
let firstName = "peter";
console.log("inside the function", firstName);
}

console.log("outside the function", firstName);

now in this case the output will be :
inside the function peter
outside the function john
this is because the let keyword has block scope. In simpler words the var has global scope and let has block scope. but when we used var in 'if' statement it did not make any block scope, because of the ES5.
I have one simple assignment for you to fully grasp the topic. In the below provided code check the output and come up with your explanation and reason for it :
let greet = "hello";
{
let greet = "good morning";

console.log("inside greet", greet);
}
console.log("outside greet", greet);

11/09/2023

Hello my enthusiast programmer:::
Do you know the difference between the outputs of the following?
console.log(test);
var test = "reactNative";

console.log(test);
let test = "JavaScript";

leave comment

Address

Dhangri Road, Mansehra
Mansehra
21300

Telephone

+923155588194

Website

Alerts

Be the first to know and let us send you an email when React Native Geeks posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The Business

Send a message to React Native Geeks:

Share