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 (===)?

@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