Urgent.News

One page, thousands of outlets. See who else covered it.

Editions

Tech

var in JavaScript

var is one of the ways to create a variable in JavaScript. A variable is a place to store a value, like a name or a number. var is mostly seen in old JavaScript code, written before 2015. Today most people use let and const instead, but it still helps to know var , especially when reading old code. Creating a Variable var name = " Abishek " ; var age = 22 ; console . log ( name ); console . log (…

JavaScript offers several methods to create variables, with "var" being one of the most common ways used historically. A variable serves as a storage space for values such as names or numbers. "var" remains prevalent in older JavaScript code written prior to 2015, although "let" and "const" are now more commonly employed.

To create a variable using "var", assign a name followed by an equals sign and the value, like so: var name = "Abishek". In this example, the variable "name" is assigned the value "Abishek". Similarly, another variable "age" is created with the integer value 22.

The value stored in a variable can be modified. For instance, the variable "age" initially set to 22 can be updated to 23 by simply assigning a new value: age = 23. The output would then display the updated value 23.

A variable can also be declared multiple times using "var" without generating an error. In such cases, the most recent declaration takes precedence. For example, var name = "Abishek" followed by var name = "Abi" results in the output "Abi", as the latter declaration overwrites the prior one.

The "var" keyword operates uniformly across the entire function, regardless of the presence of smaller code blocks within curly braces. For instance, if we declare a variable inside an if statement, it can still be accessed outside that block, provided we remain within the function. function test() { if (true) { var x = 10; } console.log(x); // works fine } test(); Consequently, even though the variable "x" was defined within the if block, it can still be utilized beyond that block as long as we stay inside the function.

Moreover, "var" variables undergo a process called hoisting. This means that JavaScript moves the variable declaration to the top of the function before executing the code. Consequently, if you attempt to log a variable before its declaration, the output will be "undefined". console.log(x); var x = 10; The output will be "undefined".

In recent times, the use of "var" has diminished in favor of "let" and "const". "let" is utilized when the variable's value may change, whereas "const" is employed when the value should remain unaltered. Understanding "var" sets the groundwork for grasping the concepts of "let" and "const".

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

i18n sin gettext: traducciones en JSON con claves de punto

Quieres que tu app hable español e inglés. Buscas cómo, y el ecosistema te empuja a gettext o Babel: ficheros .po , un paso de compilación a .mo , herramientas de extracción. Potente, sí.

  • dotkey-i18n is a Python-only i18n solution with no dependencies
  • JSON format for translations, easy to edit by anyone
  • Key notation with point, e.g. t(login.submit) navigates JSON

React Native Architecture: 8 Folder Structures for Scalable Apps

A team-lead's breakdown of 8 real React Native project architectures — what each one actually solves, where the "Domain-Driven" and "Micro-Frontend" labels get misused, and how to pick one without…

  • Flat structure suitable for prototypes and MVPs, but becomes unmanageable with growing files
  • Feature-based structure common in production apps, organizes code by product area
  • Domain-based structure aligns with business capabilities, mirrors org chart for large-scale products

FetchQuest: Spec-Driven Dog Battling on Solana Devnet

This is a submission for Weekend Challenge: Dog Days Edition What I Built FetchQuest — a tiny dog-vs-raccoon battler. You generate a dog with random stats (Speed, Bark, Chomp) and a personality tag…

  • FetchQuest is a dog-vs-raccoon battler on Solana devnet
  • Players create dogs with random stats and personality
  • Spec-driven development guided project decisions

More from Sunday 16 August →