Skip to content

Instantly share code, notes, and snippets.

@halitbatur
Created March 16, 2023 13:40
Show Gist options
  • Save halitbatur/b55bc4763eaba8fce39867937fd4d81e to your computer and use it in GitHub Desktop.
Save halitbatur/b55bc4763eaba8fce39867937fd4d81e to your computer and use it in GitHub Desktop.
Discussion Questions about JS

JS basics discussion

  • What is the difference between const and let? and why don't we use var?

  • What does return and console.log do inside a function and what is the difference between them?

  • What is a paramater in JS function and why is it there?

  • What are truthy and falsy values in JS? give some example on each

  • What is the difference between abstract equality comparison (==) and strict equality comparison (===)?

@ahmed7cf
Copy link

  • Both const and let are variables used to hold data, the only difference being, const has a static value, and is immutable, on the other hands, let is mutable, and may be reassigned. Var, on the other hand is obsolete and is not commonly used, as it does not support block-level scope.
  • console.log is a statement that is used to debug and output/print data into console. The main difference is that return terminates and returns the value into the functions.
  • A perimeter is an argument that is used to receive data form other statements and passes it into a function.
  • A falsy in JavaScript is a value that returns false, examples might be "null," "0," "Nan," "false," "", "undefined," and everything else is truthy, 1, true, "class."
  • both == and === are comparison operators, the former only compares the data between the first and second argument; does not really check the type of the data, an example would be (40 == "40") would return true, however, === is a type comparison that would also check the type of the data, meaning, (40 === "40") would result in a false value, as the first is an integer, and the second is a string.

@Laithbanat
Copy link

const and let: These are both used for variable declaration in JavaScript, but they have different purposes and scoping rules.

const: Variables declared with const are constants, meaning their values cannot be reassigned after they are initialized. This is useful when you want to create a variable that should not change throughout its scope.

let: Variables declared with let are mutable, which means their values can be reassigned. It's typically used for variables that will change during their scope.

The reason we don't use var as much anymore is due to its different scoping behavior. var is function-scoped, which can lead to unexpected behavior and bugs. const and let are block-scoped, making them more predictable and safer to use.

return vs. console.log:

return is used in a function to specify the value that the function will produce when called. It's used to pass a value back to the caller of the function.

console.log is a function used to print data to the console for debugging purposes. It doesn't affect the actual return value of a function. It's mainly used during development to inspect the values of variables or log messages.

javascript
Copy code
function add(a, b) {
return a + b;
}

function logSum(a, b) {
console.log(a + b);
}
Parameters in JS functions: Parameters are placeholders for values that you can pass into a function when calling it. They allow you to make your functions more flexible and reusable by accepting different inputs. Parameters are used to customize the behavior of a function. For example:

javascript
Copy code
function greet(name) {
console.log(Hello, ${name}!);
}
In this function, name is a parameter that you can provide when calling greet.

Truthy and Falsy values in JS:
In JavaScript, values can be evaluated as either truthy or falsy in a Boolean context (e.g., in conditional statements). Truthy values are those that are considered as true, while falsy values are considered as false. Here are some examples:

Truthy values:

Any non-empty string, e.g., "hello"
Numbers other than 0, e.g., 42
Arrays and objects, e.g., [1, 2, 3], { key: "value" }
Functions, e.g., function() {}
Falsy values:

The empty string, ""
0 (zero)
NaN (Not-a-Number)
null
undefined
false
Abstract equality comparison (==) vs. strict equality comparison (===):

== is the abstract equality operator in JavaScript, and it performs type coercion before comparing values. It tries to convert values to a common type before making the comparison. For example, 5 == "5" would be true because it converts the string "5" to the number 5 before comparing.

=== is the strict equality operator, and it does not perform type coercion. It only returns true if both the value and the type are the same. For example, 5 === "5" would be false because they have different types.

In general, it's recommended to use === for most comparisons because it avoids unexpected type coercion issues and leads to more predictable code.

@RaneemHamarneh
Copy link

1:
-the difference between const and let is that const have to be initialized and its value can't be changed later on,
-on the the other hand the let don't have to be initialized and its value can be changed,
-meanwhile the var isn't used due to its scope issus, like when redeclaring a variable the same name using var the second variable value will always be used.

2:
-console.log just prints whatever argument given to it on the console, doesn't affect the flow of the function, used for debugging purposes.
-return returns the value to the caller whether be it a function or a variable, exit the function immediately after its execution,

3:
-increases/improves usability ,reusability, abstraction and Interactivity.

4:

  • falsy values are treated as the "false" value, example: "", null, false, 0;
  • truthy value are treated as the "true" value, example: true, anything other than the falsy values.

5:
-== checks for value equality with type coercion.
-=== checks for value equality without type coercion (i.e., it checks both value and type).

@Yousef-AN
Copy link

Yousef-AN commented Sep 25, 2023

What is the difference between const and let? and var

    • const- must put a value for it and doesn’t change const - (can’t be changed)
    • var - can be assigned without a value or with initial value and we can reassign any time.
      • let (can be changed)

Why don't we use var?

  • doesn’t respect block scope and we can assign and define it anytime. and can be assigned for another variable with same name.

What do return and console.log do inside a function and what is the difference between them?

  • return = returns the value of what's inside the function or statements and return any type of data
  • console.log prints a result inside the function and the console or terminal that just prints out whatever we type inside it and type inside its statement or expression.

What is a parameter in JS function and why is it there?

  • a changeable variable that can be assigned later or used in many scenarios, it’s a name that’s listed in the function definition, it takes arguments(args) and values.

What are truthy and falsy values in JS? give some examples on each

  1. flasy value is 0 - null - undefined - nan and false - empty string. ""
  2. truly value: everything else except falsy values 1+1 = 2

What is the difference between abstract equality comparison (==) and strict equality comparison (===)?

  1. === : equal to type and value
  2. == : equal for value

room 6 :

  • Yousef Abu-Nameh
  • Hammam Abu Shehadeh
  • Hadeel Obaid
  • Ala'a Nsairat
  • Mohamad Alchehabi

@MohamadSheikhAlshabab
Copy link

  • let can redeclare but can't reassign it

  • const can't redeclare & reassign it

  • var can redeclare , reassign it. because has global scope which is unexpected behavior

  • console.log for debugging, is an object

  • return to return a value from function, is a statement

  • parameter is to pass variable to function, modifiable

  • false, NaN, null, undefine,0,"", other those values are truthy

  • Values that are coerced into true are called truthy and values that are coerced into false are called falsy.

  • strict compare type and value

  • abstract compare only value.

@Abdullah-Alawad
Copy link

Abdullah Alawad
Yara Jaber
Nour kayyali
Musab Sakhreyah
Reem Bino

Q1:
let: can be reassigned but can't be redeclared
const: can't reassigned or redeclared

We do not use var because:
	-It has global scope
	-function-scoped nature and the potential issues it can introduce

Q2:
Return: is used to specify the value that a function
should produce or result in.
console.log: we use it for debugging, also can be used to print

Q3:
-We use paramaters to pass values to functions,
makes our function flexable & makes it to work with different inputs

Q4:
Truthy: a value indicating the relation of a proposition to truth
ex. true, 1, "hello", javascript object

Falsy: A falsy value is something which evaluates to FALSE
	ex. false, null, NaN, 0, "", undefined

Q5:
==: compares the values with convert of the datatypes
===: compares the values without convert of the datatypes

The main difference between abstract equality (==) and strict equality (===)
in JavaScript is that == performs type coercion (converts types) before comparing values,
while === does not perform type coercion and checks both the value and data type.
Use === for more precise and predictable comparisons

@Hassan-AbuGareeb
Copy link

1:
-the difference between const and let is that const have to be initialized and its value can't be changed later on,
-on the the other hand the let don't have to be initialized and its value can be changed,
-meanwhile the var isn't used due to its scope issus, like when redeclaring a variable the same name using var the second variable value will always be used.

2:
-console.log just prints whatever argument given to it on the console, doesn't affect the flow of the function, used for debugging purposes.
-return returns the value to the caller whether be it a function or a variable, exit the function immediately after its execution,

3:
-increases/improves usability ,reusability, abstraction and Interactivity.

4:

  • falsy values are treated as the "false" value, example: "", null, false, 0;
  • truthy value are treated as the "true" value, example: true, anything other than the falsy values.

5:
-== checks for value equality with type coercion.
-=== checks for value equality without type coercion (i.e., it checks both value and type).

@Sanad-Alshobaki
Copy link

Sanad-Alshobaki commented Sep 25, 2023

Q1:
Let is changeable but const is unchangeable, var declarations are globally scoped or function scoped while let and const are block scoped

Q2
console.log is function that logs passed in argument to console.
return is keyword, which part of the return statement, used to end function execution.

Q3
The parameters, in a function call, are the function's arguments.
JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations.
If a function changes an argument's value, it does not change the parameter's original value.

Q4
Basically, if the variable value is false, zero, empty, null, undefined,””, or Nan, it's falsy and the code within the if block is not run.

If the variable value is anything else, such as a number that is not zero, a non-empty string, an array,”Text” or an object, it's truthy and the code in the if block is run.

Q5
The difference between them can be summed up as follows:

  • Abstract equality will attempt to resolve the data types via type coercion before making a comparison. ==
  • Strict equality will return false if the types are different. ===

Ex:
4 == "4"
>> true
4 === "4"
>> false

Sanad,Amany, Sara, Dana and Mohmmad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment