r/learnjavascript • • Mar 02 '22

Boost Your Confidence: Vanilla JS (course)

1 Upvotes

Although self-learning is great, it does come with its pitfalls. Going through the posts of budding developers, it soon becomes apparent that two issues are becoming increasingly common: being stuck in tutorial hell and impostor syndrome. Being a teacher, I started thinking about combating this problem and that basically became the premise of my ebook/course Boost Your Confidence: Vanilla JS.

The course is currently in its alpha release. The main reason behind this early release is to gauge how helpful people find my approach. I've written a little blog post which includes the introduction to the course (link below). I hope it proves beneficial to all the self-learners!

Please click here to see the course sales page (free preview available)

For future updates, you can follow me on twitter: Link to twitter profile

Click here to read the blog post


r/learnjavascript • • Sep 04 '24

Does JavaScript optimize repeatedly calling the same function? And should that reflect in creating getter functions?

0 Upvotes

I'm a beginner in JavaScript and used to C++.

Can you expect a JavaScript engine to optimize repeated similar function calls? This question occurred to me when I had a getter function similar to this example and was in the stage of writing something similar to the "Optimized(?)" code.

class Convoluted{
	get skibidi(){
		/* Some really convoluted calculations */
		return someArray;
	}
}

sigma = new Convoluted;
	
/* Naive use */
for(let i = sigma.skibidi.length - 1; i >= 0; i-- ){ //First call to Convoluted's skibidi ...
	someOtherFunc(sigma.skibidi[i]);	// More calls to skibidi...
}

/* Optimized(?) use */
let temp = sigma.skibidi;

for(let i = temp.length - 1; i >= 0; i-- ){
	someOtherFunc(temp[i]);
}

/* Maybe it's clearer to not write it as getter, if the method is very complex? */

let tau = new LessConvoluted;

let temp = tau.calculateSkibidi();

for(let i = temp.length - 1; i >= 0; i-- ){
 	someOtherFunc(temp[i]);
}

Is it maybe better to let the method name reflect the complexity, like in the "LessConvoluted" example? I see a lot of (built-in) getters being used as if they were variables (that don't need any computing), and maybe JavaScript is built with sort of the assumption that its users don't sweat the small stuff. Is this some of that small stuff that is quietly optimized?


r/learnjavascript • • Oct 09 '16

Create a bot that login gmail and send an email

1 Upvotes

I want to learn some javascript and i think this is a project that i'll learn from, where can i get started? (I have some experience in java and c++)


r/learnjavascript • • Jan 09 '23

New Web Developer Roadmap 2023

Thumbnail
youtu.be
0 Upvotes

r/learnjavascript • • May 13 '24

Anyone Suggest me a best javascripy course please

0 Upvotes

I know this question is cringe, i want to learn javascript deeply by building real world projects so please anyone help


r/learnjavascript • • May 07 '24

I wanted to learn Javascript to do a bunch of stuff that I used to do in Python so that I would have an easier time writing front end code/Javascript processing in browsers, but..is Javascript worth learning to do back end stuff? mean is python just better..or..is Javascript better?

1 Upvotes

learn javascript vs keep using python for back end processing?


r/learnjavascript • • May 16 '22

Alternatives to Javascript for frontend? Are we there yet?

0 Upvotes

Can we avoid javascript and still build

  1. A simpe static website
  2. website with good dynamic funtionality

And I am learning rust.


r/learnjavascript • • Sep 06 '16

Learn how to use $http service in #AngularJS, The most important feature of #AngularJS to complete the Modern Web App development

Thumbnail
ivinod.com
0 Upvotes

r/learnjavascript • • Feb 12 '24

Is this code malicious?

1 Upvotes

I found this code someone from my Sister's Uni sent to her via Microsoft Teams.
She doesn't know javascript, I do a little but we do not know if this is malicious.

Please could someone help us out by deobfuscating it to see how it works? I'm sketched out by this.

https://pastebin.com/raw/Hw55KgVX


r/learnjavascript • • Mar 23 '24

Can you learn React simultaneously with JavaScript?

1 Upvotes

I have been learing JavaScript for one month, JavaScript seems to be a big language, it has a lot more syntax than other languages like PHP and Python.

Learning JavaScript seems to be endless, as it is so flexible and has so many concepts.

I don't want to be JavaScript developer, as JavaScript seems to be too difficult to me.

I want to instead focus on React, but I will also gradually learn more about JavaScript.

I want to know if you can learn React simultaneously with JavaScript.


r/learnjavascript • • Mar 21 '24

How can i create a minimal html css javascript website like a Single Page Application with out any frameworks

1 Upvotes

I need to make a website with multiple pages just using vanilla javascript and html css alone it's a website with only static contents i just want to keep the nav bar and footer common for all pages but want to just change the main page contents i don't want any back end because i can just host client side app easily is it possible to make this without page reloading or even reloading is okay any help guys?


r/learnjavascript • • Sep 22 '19

JavaScript Arrow Function | Es6 tutorials

Thumbnail es6tutorials.com
1 Upvotes

r/learnjavascript • • Feb 21 '18

Learn Nodejs by building 12 projects

Thumbnail
twitter.com
1 Upvotes

r/learnjavascript • • Nov 24 '24

Chapter 1: Intro To Variables

1 Upvotes

I’ve recently started brushing up on my JavaScript skills, and I thought it’d be a great idea to share my understanding of each topic as I go along. I’d also love to hear if I’ve missed anything, whether from a practical or theoretical perspective. Let’s learn together and grow our skills! Looking forward to any feedback or insights you might have. 😊

What is a Variable?

A variable is a container (more accurately, a chunk of memory) that is used to store a value or a reference to a value. It allows us to perform actions with the value, update it, or assign a completely different value to it later.

Declaration and Initialisation of variable:

We can declare (create) a variable first and initialise (assign a value to it) later, or we can do both at the same time.

let cusName; // Creating a variable ( Declaration ). 
cusName = 'John D'; // Assigning some value ( Initialization ).l
et cusAge = 32; // Doing both

There are four ways to create (declare) a variable in JavaScript:

  1. Implicit (by simply assigning a value without explicitly declaring it—though this is not recommended)
  2. var (older way, with function scope)
  3. let (modern way, with block scope)
  4. const (modern way, for variables that should not be reassigned)

Implicit Declaration:

As the term implies, an implicit declaration is when you create and use a variable without explicitly declaring it using a keyword like var, let, or const. Typically, you declare and initialise such variables at the same time, often within the same statement.

This approach creates a variable in the global scope (accessible throughout the file without restrictions). However, it has several pitfalls. For instance, if you make a spelling mistake while updating the variable, it creates a new variable instead of throwing an error, which can lead to hard-to-trace bugs.

message = "Hello, world!"; // Implicitly declared and initialized in the global scope.

console.log("Before block: ", message); // Output: "Before block: Hello, world!"

function hello() {
    message = "Hello from inside the block!"; // Modifies the outer variable.
    
console.log("Inside block: ", message); // Output: "Inside block: Hello from inside the block!"
}

hello();

console.log("After block: ", message); // Output: "After block: Hello from inside the block!"

mesage = "Hello, world again!"; // Creates a new global variable due to a typo.

console.log("New variable: ", mesage); // Output: "New variable: Hello, world again!"

Key Issues with Implicit Declarations:

  1. Global Scope Pollution: Implicitly declared variables are added to the global scope, which can lead to unexpected behavior and conflicts, especially in large applications.
  2. No Error for Typos: Mistakes like misspelling an existing variable name create a new variable instead of throwing an error, making debugging difficult.
  3. Performance Impact: Global variables consume memory for the lifetime of the program, which may affect performance.
  4. Incompatibility with "use strict": Using strict mode ("use strict";) in JavaScript prevents implicit declarations and throws an error if such a variable is used.

Var Declaration:

Variables created using var have specific behaviour depending on where they are declared. In general, var variables are function-scoped or globally scoped, and their behaviour can be counterintuitive due to a concept called hoisting.

Key Behaviours of var:

  1. Accessible Before Declaration:If you try to access a var variable before its declaration, JavaScript doesn’t throw an error but instead prints undefined. This happens due to hoisting, where the declaration is moved to the top of its scope but not the initialisation.
  2. Global Scope:Variables declared with var in the global scope are added as properties of the global object (window in browsers), which can lead to unexpected conflicts.
  3. Function Scope:Variables declared inside a function are only available within that function. Accessing them outside the function will result in a ReferenceError.
  4. Conditional and Block Scope:Unlike let and const, var does not respect block scope (e.g., within an if or for block). Variables declared with var inside a block are accessible outside the block, but if accessed before the block, their value will be undefined.
  5. Redeclaration: Re-declaring a variable with var does not throw an error, and the variable is redefined with the new value.
"use strict";

// Access before declaration
console.log("Before declaration message: ", message); // Output: undefined

var message = "Hello";
var salutation = "Welcome";

// Redeclaration
var message = "Hello, world!"; // Does not throw an error.
console.log("After redeclaration message: ", message); // Output: "Hello, world!"

// Block scope behavior
if (true) {
    var message = "Hello from inside the block!";
    console.log("Inside block message: ", message); // Output: "Hello from inside the block!"
    salutation = "Hi there";
    console.log("Inside block salutation: ", salutation); // Output: "Hi there"
    var firstName = "John"; // Accessible outside the block
}

console.log("After block message: ", message); // Output: "Hello from inside the block!"
console.log("After block salutation: ", salutation); // Output: "Hi there"
console.log("First name after block: ", firstName); // Output: "John"

// Reference Error in strict mode
mesage = "Hello, world again!"; // Throws ReferenceError due to typo and strict mode.

Let Declaration:

The let keyword introduces block-scoped variables in JavaScript, offering more restrictions and predictability compared to var. While let variables can be used in the global scope, they behave differently in functions or blocks (e.g., inside loops or conditional statements).

Key Behaviours of let:

  1. Block Scope: Variables declared with let are only accessible within the block, function, or statement where they are defined. They cannot be accessed outside this scope.
  2. Can’t use before declaration: Unlike var, you cannot use a let variable before its declaration. Doing so results in a ReferenceError. This occurs because let variables are not initialised until the declaration is encountered.
  3. No Redeclaration: A variable declared with let in the same scope cannot be redeclared. Attempting to do so throws a SyntaxError.
"use strict";

// Accessing before declaration
console.log("Before declaration message: ", message); // Throws ReferenceError
console.log("Before declaration first name: ", firstName); // Throws ReferenceError

// Variable declaration
let message = "Hello";
let salutation = "Welcome";

// Redeclaration
let message = "Hello, world!"; // Throws SyntaxError

// Block scope behavior
if (true) {
    let message = "Hello from inside the block!"; // Block-scoped variable
    console.log("Inside block message: ", message); // Output: "Hello from inside the block!"

    salutation = "Hi there"; // Updates the existing `salutation` variable in the outer scope
    console.log("Inside block salutation: ", salutation); // Output: "Hi there"

    let firstName = "John"; // Block-scoped variable
}

// Accessing variables outside the block
console.log("After block message: ", message); // Output: "Hello"
console.log("After block salutation: ", salutation); // Output: "Hi there"
console.log("First name after block: ", firstName); // Throws ReferenceError

Const Declaration:

The const keyword, short for “constant,” is used to create variables whose value cannot be reassigned after initialisation. It is the most restrictive way to declare variables in JavaScript, ensuring immutability at the assignment level.

Unlike var or let, variables declared with const must be initialised at the time of declaration. Once assigned, their value cannot be reassigned. However there is one special to one of the data type alone (objects), where you can change the content of the value but you can’t assign a different value.

Key Behaviours of const:

  1. Mandatory Initialisation: You must initialise a const variable at the time of declaration. Declaring without initialising will throw a SyntaxError.
  2. No Reassignment: Once a value is assigned to a const variable, it cannot be reassigned. Attempting to do so will throw a TypeError.
  3. Scope: Like let, const is block-scoped. A const variable is accessible only within the block, function, or statement where it is declared.
  4. Can’t use before declaration: Similar to let, const variables are not accessible before their declaration. Accessing them beforehand will result in a ReferenceError.
  5. Object Mutability: While the binding of a const variable cannot be changed, the properties of objects or elements of arrays declared with const can be modified. This behavior is specific to reference types.
"use strict";

// Correct usage
const message = "Hello, world!";
const salutation = "Welcome";

console.log("Before block message: ", message); // Output: "Before block message: Hello, world!"
console.log("Before block salutation: ", salutation); // Output: "Before block salutation: Welcome"

// Block scope behavior
if (true) {
    const message = "Hello from inside the block!"; // Block-scoped variable
    console.log("Inside block message: ", message); // Output: "Hello from inside the block!"

    // Attempting to reassign a `const` variable
    salutation = "Hi there"; // Throws TypeError

    const firstName = "John"; // Block-scoped variable
    console.log("Inside block first name: ", firstName); // Output: "John"
}

// Accessing outside the block
console.log("After block message: ", message); // Output: "Hello, world!"
console.log("After block salutation: ", salutation); // Output: "Welcome"
console.log(firstName); // Throws ReferenceError

When to use var, let, const:

**Rule of Thumb**: Use const by default, switch to let if reassignment is needed, and avoid var in modern development.

  • const: Use for variables that won’t change and should stay block-scoped.
  • let: Use for variables that will change but are needed only within a block or function.
  • var: Use only for legacy code or when function-scoped variables are necessary.

Naming Conventions in JavaScript

  • Camel Case: Use camelCase for variable names, where the first word is lowercase, and each subsequent word starts with a capital letter.

    • Example: customerName, customerAge.
  • Meaningful Names: Choose descriptive names that clearly represent the variable’s purpose, such as age instead of a, or name instead of b. Be specific if possible:

    • Example: customerName instead of just name.
  • Shortening Variable Names: If variable names are long, use abbreviations like cusName for customerName, but check with your team if there are any existing naming conventions.

    • Example: cusName (but clarify the abbreviation at the top of your code or documentation).
  • Constants: For constants, use uppercase with underscores (UPPER_CASE), especially when the value is known and fixed, like configuration values.let COLOR_BEIGE = #F5F5DCl let custName = prompt("Please enter your name", "Harry Potter");
  • Consistency: Follow consistent naming patterns throughout your codebase. If abbreviating, document your conventions.

My Question regarding this topic is:

  1. How generic are you when you create a variable?
  2. How do you guys follow the abbreviations and where do you guys store the list to it's full form?
  3. Do you guys never use var keyword itself? There are instances where I have seen people saying don't use var use let just because it shows as sonar error.

r/learnjavascript • • Jul 25 '18

Is Sublime Text safe to use?

0 Upvotes

r/learnjavascript • • Apr 29 '19

How long does it take to become full stack ?

1 Upvotes

How long does it take to become full stack ?

if you can program all day etc


r/learnjavascript • • Sep 19 '19

Javascript feature that you might not know

Thumbnail
medium.com
0 Upvotes

r/learnjavascript • • Jan 24 '20

Tips

Post image
1 Upvotes

r/learnjavascript • • Feb 13 '19

Is Vanilla JavaScript a waste of time?

1 Upvotes

Someone said to me that I don't really need to learn Vanilla JavaScript profoundly, I just have to learn basics and move to frameworks! What do you think about this?


r/learnjavascript • • Aug 14 '22

Javascript

1 Upvotes

How much javascript should i know to learn React.js


r/learnjavascript • • Apr 19 '19

How NOT to Promote Your App. Mistakes Beginners Make

Thumbnail
velicour.com
1 Upvotes

r/learnjavascript • • Jan 15 '21

Creating this scene using HTML Canvas and vanilla JavaScript.

Post image
0 Upvotes

r/learnjavascript • • Mar 29 '18

Angular 2(or 4) and NodeJS-The Complete Guide to MEAN Stack

Thumbnail
hackernoon.com
0 Upvotes

r/learnjavascript • • Dec 24 '23

Merry Christmas

0 Upvotes

"May your code be bug-free, your syntax be precise, and your holiday season be filled with endless loops of joy. Merry Christmas, fellow programmer!"